w3resource

NumPy Binary operations: invert() function

numpy.invert() function

The invert() function is used to compute bit-wise inversion, or bit-wise NOT, element-wise.

Version: 1.15.0

Syntax:

numpy.invert(x, /, out=None, *, where=True, casting=’same_kind’, order=’K’, dtype=None,
subok=True[, signature, extobj ]) = <ufunc 'invert'>

Parameter:

Name Description Required /
Optional
x Only integer and boolean types are handled. Required
out 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. Optional
where Values of True indicate to calculate the ufunc at that position, values of False indicate to leave the value in the output alone. Optional
**kwargs For other keyword-only arguments.

Return value:

out: [ndarray or scalar]
Result: This is a scalar if x is a scalar.

Example-1: numpy.invert() function

import numpy as np
>>> np.invert(np.array([13], dtype=uint16))
array([65522], dtype=uint16)
>>> np.binary_repr(1, width=16)
'0000000000000001'
>>> np.binary_repr(65522, width=16)
'1111111111110010'

Example-2: numpy.invert() function

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

Python Code Editor:

Previous: bitwise_xor()
Next: left_shift()