Python | Numpy MaskedArray.__rsub__
numpy.ma.MaskedArray class
is a subclass of ndarray designed to manipulate numerical arrays with missing data. With the help of Numpy MaskedArray.__rsub__ we can subtract a particular value that is provided as a parameter in the MaskedArray.__rsub__() method. Value will be subtracted from each and every element in a numpy array.
Syntax: numpy.MaskedArray.__rsub__
Return: Subtract self from other, and return a new masked array.
Example #1 :
In this example we can see that each and every element in an array is subtracted with the value given as a parameter in method MaskedArray.__rsub__(). Remember one thing it wouldn’t work for double type values.
import numpy as np
gfg = np.ma.array([ 11 , 22 , 23 , 24 , 25 ])
print (gfg.__rsub__( 5 ))
|
Output:
[ -6 -17 -18 -19 -20]
Example #2:
import numpy as np
gfg = np.ma.array([[ 21 , 22 , 23 , 24 , 25 ],
[ 26 , 25 , 24 , 23 , 22 ]])
print (gfg.__rsub__( 5 ))
|
Output:
[[-16 -17 -18 -19 -20]
[-21 -20 -19 -18 -17]]
Last Updated :
27 Mar, 2019
Like Article
Save Article
Share your thoughts in the comments
Please Login to comment...