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

NumPy | Python Methods and Functions

Using the Numpy numpy.ndarray .__ or __ () method, we can get the OR elements by the value provided as a parameter in numpy.ndarray .__ or __ () .

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

Return: self | value

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

# 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 .__ or __ () method

print (gfg .__ or __ ( 2 ))

Exit:

 [3 2 3 6 7] 

Example # 2:

# 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 the method ndarray .__ or __ ()

print (g fg .__ or __ ( 1 ))

Exit:

 [[1 3 3 5 5] [7 5 5 3 3]] 




Get Solution for free from DataCamp guru