Python | Numpy MaskedArray .__ mod__



numpy.ma.MaskedArray class is a subclass of ndarray for manipulating numeric arrays with missing data. With Numpy MaskedArray .__ mod__ , each element in the masked array works with a binary operator, i.e. mod (%). Remember we can use any type of value in the array, and the value for mod is applied as a parameter in MaskedArray .__ mod __ ().

Syntax: numpy. MaskedArray .__ mod__

Return: Return self% value.

Example # 1:
We can see that the value we passed through the MaskedArray .__ mod __ () method is used to perform a mod operation on each element of the array.

# import important module in python

import numpy as np 

 
# make an array with NumPy

gfg = np.ma.array ([ 1 , 2.5 , 3 , 4.8 , 5 ]) 

 
# applying the MaskedArray method .__ mod __ ()

print (gfg .__ mod __ ( 2 )) 

Output:

 [1.0 0.5 1.0 0.7999999999999998 1.0] 

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.45 , 5 ], 

[ 6 , 5.5 , 4 , 3 , 2.62 ]] ) 

 
# applying the MaskedArray method .__ mod __ ()

print (gfg .__ mod __ ( 3 )) 

Exit:

 [[1.0 2.0 0.0 1.4500000000000002 2.0] [0.0 2.5 1.0 0.0 2.62]]