# xarray.ufuncs.bitwise_invert

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

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

Documentation from numpy:

Compute bit-wise inversion, or bit-wise NOT, element-wise.

Computes the bit-wise NOT of the underlying binary representation of
the integers in the input arrays. This ufunc implements the C/Python
operator `~`.

For signed integer inputs, the bit-wise NOT of the absolute value is
returned. In a two’s-complement system, this operation effectively flips
all the bits, resulting in a representation that corresponds to the
negative of the input plus one. This is the most common method of
representing signed integers on computers <sup>[1](#id2)</sup>. An N-bit two’s-complement
system can represent every integer in the range $-2^{N-1}$ to
$+2^{N-1}-1$.

* **Parameters:**
  * **x** ([array_like](https://numpy.org/doc/stable/glossary.html#term-array_like)) – Only integer and boolean types are handled.
  * **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:**
  **out** ([`ndarray`](https://numpy.org/doc/stable/reference/generated/numpy.ndarray.html#numpy.ndarray) or [scalar](../user-guide/terminology.html.md#term-scalar)) – Result.
  This is a scalar if x is a scalar.

#### SEE ALSO
[`bitwise_and`](xarray.ufuncs.bitwise_and.html.md#xarray.ufuncs.bitwise_and), [`bitwise_or`](xarray.ufuncs.bitwise_or.html.md#xarray.ufuncs.bitwise_or), [`bitwise_xor`](xarray.ufuncs.bitwise_xor.html.md#xarray.ufuncs.bitwise_xor), [`logical_not`](xarray.ufuncs.logical_not.html.md#xarray.ufuncs.logical_not)

`binary_repr`
: Return the binary representation of the input number as a string.

### Notes

`numpy.bitwise_not` is an alias for invert:

```pycon
>>> np.bitwise_not is np.invert
True
```

### References

* <a id='id2'>**[1]**</a> Wikipedia, “Two’s complement”, [https://en.wikipedia.org/wiki/Two’s_complement](https://en.wikipedia.org/wiki/Two's_complement)

### Examples

<div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesShowIframe('3fdf2510-f29d-48ea-8c95-92646303d6ee','4be7425c-a15e-492c-87cd-69708e00ed68','9a29985b-3f63-4951-a676-628af84cbb26','../lite/tree/../notebooks/index.html?path=b68d5ffd_0c31_4e05_9e71_5455a2d0005a.ipynb','None')">Try it in your browser!</button></div>
```pycon
>>> import numpy as np
```

We’ve seen that 13 is represented by `00001101`.
The invert or bit-wise NOT of 13 is then:

```pycon
>>> x = np.invert(np.array(13, dtype=np.uint8))
>>> x
np.uint8(242)
>>> np.binary_repr(x, width=8)
'11110010'
```

The result depends on the bit-width:

```pycon
>>> x = np.invert(np.array(13, dtype=np.uint16))
>>> x
np.uint16(65522)
>>> np.binary_repr(x, width=16)
'1111111111110010'
```

When using signed integer types, the result is the bit-wise NOT of
the unsigned type, interpreted as a signed integer:

```pycon
>>> np.invert(np.array([13], dtype=np.int8))
array([-14], dtype=int8)
>>> np.binary_repr(-14, width=8)
'11110010'
```

Booleans are accepted as well:

```pycon
>>> np.invert(np.array([True, False]))
array([False,  True])
```

The `~` operator can be used as a shorthand for `np.invert` on
ndarrays.

```pycon
>>> x1 = np.array([True, False])
>>> ~x1
array([False,  True])
```

<div id="9a29985b-3f63-4951-a676-628af84cbb26" class="try_examples_outer_iframe  hidden"><div class="try_examples_button_container"><button class="try_examples_button" onclick="window.tryExamplesHideIframe('3fdf2510-f29d-48ea-8c95-92646303d6ee','9a29985b-3f63-4951-a676-628af84cbb26')">Go Back</button><button class="try_examples_button" onclick="window.openInNewTab('3fdf2510-f29d-48ea-8c95-92646303d6ee','9a29985b-3f63-4951-a676-628af84cbb26')">Open In Tab</button></div><div id="4be7425c-a15e-492c-87cd-69708e00ed68" class="jupyterlite_sphinx_iframe_container"></div></div><script>document.addEventListener("DOMContentLoaded", function() {window.loadTryExamplesConfig("../try_examples.json");});</script>
