# xarray.ufuncs.sign

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

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

Documentation from numpy:

Returns an element-wise indication of the sign of a number.

The sign function returns `-1 if x < 0, 0 if x==0, 1 if x > 0`.  nan
is returned for nan inputs.

For complex inputs, the sign function returns `x / abs(x)`, the
generalization of the above (and `0 if x==0`).

#### Versionchanged
Changed in version 2.0.0: Definition of complex sign changed to follow the Array API standard.

* **Parameters:**
  * **x** ([array_like](https://numpy.org/doc/stable/glossary.html#term-array_like)) – Input values.
  * **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)) – The sign of x.
  This is a scalar if x is a scalar.

#### SEE ALSO
[`signbit`](xarray.ufuncs.signbit.html.md#xarray.ufuncs.signbit), [`copysign`](xarray.ufuncs.copysign.html.md#xarray.ufuncs.copysign)

### Notes

There is more than one definition of sign in common use for complex
numbers.  The definition used here, $x/|x|$, is the more common
and useful one, but is different from the one used in numpy prior to
version 2.0, $x/\sqrt{x*x}$, which is equivalent to
`sign(x.real) + 0j if x.real != 0 else sign(x.imag) + 0j`.

### Examples

<div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesShowIframe('5cd3f869-e0ca-4569-9adc-4d9026261277','25c9fccb-cfbc-4b0e-943d-f3854b795a9c','da928195-f789-4be4-8945-48b6bfd482f6','../lite/tree/../notebooks/index.html?path=da336c0e_3b47_4cb1_af85_1861d7bef18a.ipynb','None')">Try it in your browser!</button></div>
```pycon
>>> import numpy as np
>>> np.sign([-5., 4.5])
array([-1.,  1.])
>>> np.sign(0)
0
>>> np.sign([3-4j, 8j])
array([0.6-0.8j, 0. +1.j ])
```

<div id="da928195-f789-4be4-8945-48b6bfd482f6" class="try_examples_outer_iframe  hidden"><div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesHideIframe('5cd3f869-e0ca-4569-9adc-4d9026261277','da928195-f789-4be4-8945-48b6bfd482f6')">Go Back</button><button class="try_examples_button" onclick="window.openInNewTab('5cd3f869-e0ca-4569-9adc-4d9026261277','da928195-f789-4be4-8945-48b6bfd482f6')">Open In Tab</button></div><div id="25c9fccb-cfbc-4b0e-943d-f3854b795a9c" class="jupyterlite_sphinx_iframe_container"></div></div><script>document.addEventListener("DOMContentLoaded", function() {window.loadTryExamplesConfig("../try_examples.json");});</script>
