Python | Numpy MaskedArray .__ imod__



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

Syntax: numpy .MaskedArray .__ imod __ (other)

Return: Return self% = value.

Example # 1:
In this example, we can see that the value we passed through the MaskedArray method .__ imod __ () 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 , 7 , 5 ]) 

 
# applying MaskedArray .__ imod __ () method

print (gfg .__ imod __ ( 2 )) 

Exit:

 [1.0 0.5 1.0 1.0 1.0] 

Example # 2:

Exit:

 [[4.0 2.0 1.0 2.0 4.0] [4.0 3.5 4.0 1.0 1.0]] 

# import important module in python

import numpy as np 

 
 # make an array with NumPy

gfg = np.ma.array ([[ 14 , 22 , 31 , 47 , 54 ], 

[ 64 , 53.5 , 44 , 36 , 21 ]]) 

 
# applying MaskedArray .__ imod __ () method

print (gfg .__ i mod __ ( 5 ))