Python | Numpy MaskedArray .__ eq__

Arrays | NumPy | Python Methods and Functions

numpy.ma.MaskedArray class is a subclass of ndarray for manipulating numeric arrays with missing data. With the Numpy operator MaskedArray .__ eq__ we can determine which element of the array is equal to the value specified in the parameter.

Syntax : numpy.MaskedArray .__ eq__

Return: self == value

Example # 1:
In this example, we can see that after applying MaskedArray .__ eq __ () we get a simple boolean array that can tell us which element in the array is equal to the supplied parameter.

# import important module in python

import numpy as np 

 
# make an array with NumPy

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

 
# applying the MaskedArray method .__ eq __ ()

print (gfg .__ eq __ ( 4 )) 

Output:

 [False False False True False False] 

Example # 2:

# import an important module into python

import numpy as np 

 
# make an array with NumPy

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

[ 6 , 5 , 4 , 3 , 2 , 1 ]]) 

  
# applying the MaskedArray method .__ eq __ ()

print (gfg .__ eq __ ( 4 )) 

Exit:

 [[False False False True False False ] [False False True False False False]] 




Get Solution for free from DataCamp guru