# xarray.ufuncs.negative

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

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

Documentation from numpy:

Numerical negation, element-wise.

* **Parameters:**
  * **x** ([array_like](https://numpy.org/doc/stable/glossary.html#term-array_like) or [scalar](../user-guide/terminology.html.md#term-scalar)) – Input array.
  * **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)) – Returned array or scalar: y = -x.
  This is a scalar if x is a scalar.

### Examples

<div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesShowIframe('e4589c91-8e76-41d5-8fab-23734fa5535d','a3cee082-081d-4600-b5f0-e6e1e84b3d14','75519e97-f061-4a3f-9695-c5bf61e5ba98','../lite/tree/../notebooks/index.html?path=3a96ed47_eb62_44e3_a0e3_d975ffa113bf.ipynb','None')">Try it in your browser!</button></div>
```pycon
>>> import numpy as np
>>> np.negative([1.,-1.])
array([-1.,  1.])
```

The unary `-` operator can be used as a shorthand for `np.negative` on
ndarrays.

```pycon
>>> x1 = np.array(([1., -1.]))
>>> -x1
array([-1.,  1.])
```

<div id="75519e97-f061-4a3f-9695-c5bf61e5ba98" class="try_examples_outer_iframe  hidden"><div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesHideIframe('e4589c91-8e76-41d5-8fab-23734fa5535d','75519e97-f061-4a3f-9695-c5bf61e5ba98')">Go Back</button><button class="try_examples_button" onclick="window.openInNewTab('e4589c91-8e76-41d5-8fab-23734fa5535d','75519e97-f061-4a3f-9695-c5bf61e5ba98')">Open In Tab</button></div><div id="a3cee082-081d-4600-b5f0-e6e1e84b3d14" class="jupyterlite_sphinx_iframe_container"></div></div><script>document.addEventListener("DOMContentLoaded", function() {window.loadTryExamplesConfig("../try_examples.json");});</script>
