Saturday, November 16, 2024
Google search engine
HomeLanguagesPython | Numpy MaskedArray.__imod__

Python | Numpy MaskedArray.__imod__

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)) 


Output:

[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)) 


Output:

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

Dominic Rubhabha-Wardslaus
Dominic Rubhabha-Wardslaushttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Recent Comments