# xarray.ufuncs.trunc

### xarray.ufuncs.trunc *= <xarray.ufuncs._unary_ufunc object>*

xarray specific variant of `numpy.trunc()`. Handles xarray objects by dispatching to the appropriate function for the underlying array type.

Documentation from numpy:

Return the truncated value of the input, element-wise.

The truncated value of the scalar x is the nearest integer i which
is closer to zero than x is. In short, the fractional part of the
signed number x is discarded.

* **Parameters:**
  * **x** ([array_like](https://numpy.org/doc/stable/glossary.html#term-array_like)) – Input data.
  * **out** ([`ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray), [`None`](https://docs.python.org/3/builtins/constants.html#None), or [`tuple`](https://docs.python.org/3/builtins/stdtypes.html#tuple) of [`ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray) and [`None`](https://docs.python.org/3/builtins/constants.html#None), *optional*) – A location into which the result is stored. If provided, it must have
    a shape that the inputs broadcast to. If not provided or None,
    a freshly-allocated array is returned. A tuple (possible only as a
    keyword argument) must have length equal to the number of outputs.
  * **where** ([array_like](https://numpy.org/doc/stable/glossary.html#term-array_like), *optional*) – This condition is broadcast over the input. At locations where the
    condition is True, the out array will be set to the ufunc result.
    Elsewhere, the out array will retain its original value.
    Note that if an uninitialized out array is created via the default
    `out=None`, locations within it where the condition is False will
    remain uninitialized.
  * **\*\*kwargs** – For other keyword-only arguments, see the
    [ufunc docs](https://numpy.org/doc/stable/reference/ufuncs.html#ufuncs-kwargs).
* **Returns:**
  **y** ([`ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray) or [scalar](../user-guide/terminology.html.md#term-scalar)) – The truncated value of each element in x.
  This is a scalar if x is a scalar.

#### SEE ALSO
[`ceil`](xarray.ufuncs.ceil.html.md#xarray.ufuncs.ceil), [`floor`](xarray.ufuncs.floor.html.md#xarray.ufuncs.floor), [`rint`](xarray.ufuncs.rint.html.md#xarray.ufuncs.rint), `fix`

### Examples

<div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesShowIframe('adbf28a2-c960-4598-8dd8-8db5c26c495b','be7e773f-a456-47a4-9367-b665c153c980','e727ae3a-8130-4673-bfb7-5770410a3465','../lite/tree/../notebooks/index.html?path=41520956_c52a_43ea_a5fa_b43b2e9663a2.ipynb','None')">Try it in your browser!</button></div>
```pycon
>>> import numpy as np
>>> a = np.array([-1.7, -1.5, -0.2, 0.2, 1.5, 1.7, 2.0])
>>> np.trunc(a)
array([-1., -1., -0.,  0.,  1.,  1.,  2.])
```

<div id="e727ae3a-8130-4673-bfb7-5770410a3465" class="try_examples_outer_iframe  hidden"><div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesHideIframe('adbf28a2-c960-4598-8dd8-8db5c26c495b','e727ae3a-8130-4673-bfb7-5770410a3465')">Go Back</button><button class="try_examples_button" onclick="window.openInNewTab('adbf28a2-c960-4598-8dd8-8db5c26c495b','e727ae3a-8130-4673-bfb7-5770410a3465')">Open In Tab</button></div><div id="be7e773f-a456-47a4-9367-b665c153c980" class="jupyterlite_sphinx_iframe_container"></div></div><script>document.addEventListener("DOMContentLoaded", function() {window.loadTryExamplesConfig("../try_examples.json");});</script>
