Python | Numpy numpy.ndarray .__ and __ ()



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

Syntax: ndarray .__ and __ ($ 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 .__ and __ () .

# 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 .__ and __ () methods

print (gfg .__ and __ ( 2 ))

Exit:

 [0 2 2 0 0] 

Example # 2:

Exit:

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

# import 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 ndarray methods. __ and __ ()

print (gfg .__ and __ ( 1 ))