The invert()
function is one of the many useful functions provided by NumPy.
The invert()
function is used to invert the NumPy array. For example, if the array is a signed integer, then the invert()
function will return its 2’s complement. In medical image processing, if the color of the image is black, then the invert()
function will convert its color to white, and vice versa.
This is the syntax that is required to use this function:
numpy.invert(array)
array
: This parameter denotes the input array. Please note that this function only supports integer and Boolean types.If the array
parameter value is a scalar, this function will return scalar.
We’ll use the invert()
method with an array of signed numbers in this example:
import numpy as nparr = [-8, 20, -65]print ("The Input array is: ", arr)result = np.invert(arr)print ("The Output array after inversion: ", result)
We’ll use the invert()
method with an array of unsigned numbers in this example:
import numpy as nparr = [4, 56, 89]print ("The Input array is: ", arr)result = np.invert(arr)print ("The Output array after inversion: ", result)
In this shot, we went through the invert()
function’s syntax, parameters, the values returned by it, and two code examples of the function in use.
Free Resources