Python | Numpy MaskedArray .__ rsub__



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

Syntax: numpy.MaskedArray .__ rsub__

Return: Subtract self from other, and return a new masked array.

Example # 1:
In this example, we see that each element of the array is subtracted from the value specified as a parameter in the MaskedArray .__ rsub __ () 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 ([ 11 , 22 , 23 , 24 , 25 ]) 

 
# applying MaskedArray .__ rsub __ () method

print  (gfg .__ rsub __ ( 5 )) 

Exit:

 [-6 -17 -18 -19 -20] 

Example # 2:

# import important module into python

import numpy as np 

 
# make an array with NumPy

gfg = np.ma.array ([[ 21 , 22 , 23 , 24 , 25 ], 

[ 26 , 25 , 24 , 23 , 22 ]]) 

 
# applying MaskedArray .__ rsub __ () method

print (gfg .__ rsub __ ( 5 )) 

Exit:

 [[-16 -17 -18 -19 -20] [-21 -20 -19 -18 -17]]