Python | Numpy MaskedArray .__ isub__



numpy.ma.MaskedArray class is a subclass of ndarray for manipulating numeric arrays with missing data. With Numpy MaskedArray .__ isub__ we can subtract a specific value that is provided as a parameter in the MaskedArray .__ isub __ () method. The value will be subtracted for each item in the numpy array.

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

Return: Subtract other to self in-place.

Example # 1:
In this example, we see that each element of the array is subtracted with a value specified as a parameter in the MaskedArray .__ isub __ () method. Remember one thing, this will not work for double type values.

# import important module into python

import numpy as np 

 
# make an array with NumPy

gfg = np.ma.array ([ 1 , 2 , 3 , 4.7 , 5.2 ]) 

 
# applying MaskedArray .__ isub __ () method

print < / code> (gfg .__ isub __ ( 5 )) 

Exit:

 [-4. -3. -2. -0.3 0.2] 

Example # 2:

# import important module into python

import numpy as np 

  
# make an array with NumPy

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

[ 6 , 5 , < code class = "value"> 4 , 3 , 2 ]]) 

 
# applying MaskedArray .__ isub __ () method

print (gfg .__ isub __ ( 5 )) 

Exit:

 [[-4 -3 -2 -1 0] [1 0 -1 - 2 -3]]