  # Python | Numpy numpy.ndarray .__ invert __ ()

NumPy | Python Methods and Functions

` Numpy numpy.ndarray .__ invert __ () ` can invert array elements. We don`t need to provide any type of parameter, but remember that this method only works for integer values.

Syntax: ndarray. __invert __ (\$ self, /)

Return: ~ self

Example # 1:
In this example, we can see that each element in the array works with a unary operator, i.e. ~ using the ` ndarray .__ invert __ () ` method.

 ` # import important module in python ` ` import ` ` numpy as np `   ` # make an array with NumPy ` ` gfg ` ` = ` ` np.array ([` ` 1 ` ` , ` ` 2 ` `, ` ` 3 ` `, ` ` 4 ` `, ` ` 5 ` `]) `   ` # applying the ndarray method .__ invert __ () ` ` print ` ` (gfg .__ invert __ ()) `

Exit:

` [-2 -3 -4 -5 -6] `

Example # 2:

 ` # import important module in python ` ` import ` ` numpy as np ` `   # make an array with NumPy `` gfg = np.array ([[ 1 , 2 , 3 , 4 , 5 ] , [ 6 , 5 , 4 , 3 , 2 ]])   # applying the ndarray .__ invert __ () method print (gfg .__ invert __ () ) `

Exit:

` [[ -2 -3 -4 -5 -6] [-7 -6 -5 -4 -3]] `