numpy.ma.MaskedArray class
is a subclass of ndarray designed to manipulate numerical arrays with missing data. With the help of Numpy MaskedArray.__imod__ we can get every element in an array is operated on binary operator i.e mod(%). Remember we can use any type of values in an array and value for mod is applied as the parameter in MaskedArray.__imod__() method.
Syntax: numpy.MaskedArray.__imod__(other)
Return: Return self%=value.
Example #1 :
In this example we can see that value that we have passed through MaskedArray.__imod__() method is used to perform the mod operation with every element of an array.
# import the 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 )) |
[1.0 0.5 1.0 1.0 1.0]
Example #2:
# import the 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.__imod__( 5 )) |
[[4.0 2.0 1.0 2.0 4.0] [4.0 3.5 4.0 1.0 1.0]]