Python | Numpy MaskedArray .__ divmod__

numpy.ma.MaskedArray class is a subclass of ndarray for manipulating numeric arrays with missing data. Using Numpy MaskedArray .__ divmod__ we get two arrays, one of which has elements that are divisible by the values ​​provided in the numpy.ma .__ divmod __ () method, and the second — elements that perform a mod operation with the same value as in numpy. .ma .__ divmod __ () method.

Syntax: numpy.MaskedArray .__ divmod__

Return: Return divmod (self, value).

Example # 1:
In this example, we can see that using the MaskedArray method .__ divmod __ ( ) we get two arrays. One with a division with the value that is passed as a parameter, and the other with the mod values.

# import important module in python

import numpy as np 

  
# make an array with NumPy

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

 
# applying the MaskedArray method .__ divmod __ ()

  print (gfg .__ divmod __ ( 3 )) 

Exit:

 (masked_array (data = [0 0 1 1 1], mask = [False False False False False], fill_value = 999999), masked_array (data = [1 2 0 1 2], mask = [False False False False False], fill_value = 999999)) 

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 , 5 , 4 , 3 , 2 ]] ) 

 
# applying the MaskedArray method .__ divmod __ ()

print (gfg .__ divmod __ ( 3 )) 

Output:

 (masked_array (data = [[0 0 1 1 1] [2 1 1 1 0]], mask = [[False False False False False] [False False Fals e False False]], fill_value = 999999), masked_array (data = [[1 2 0 1 2] [0 2 1 0 2]], mask = [[False False False False False] [False False False False False]] , fill_value = 999999))