Python | Numpy ndarray .__ Iand __ ()



Using the Numpy ndarray .__ iand __ () method, we can get the elements that are added to the value specified as a parameter in numpy.ndarray .__ iand __ ( ) .

Syntax: ndarray .__ iand __ ($ self, value, /)

Return: self & amp; = value

Example # 1:
In this example, we see that each element is assigned the value passed as a parameter to ndarray .__ iand __ () .

# import important module into python

import numpy as np

 
# make an array with NumPy

gfg = np.array ([ 1 , 2 , 3 , 4 , 5 ])

 
# applying the ndarray .__ iand __ () method

print (gfg .__ iand __ ( 2 ))

Exit:

 [0 2 2 0 0] 

Example # 2:

# import an important module into 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 method .__ iand __ ( )

print (gfg .__ iand __ ( 1 ))

Exit:

 [[1 0 1 0 1] [0 1 0 1 0]]