Saturday, May 9, 2026
HomeLanguagesPython | Numpy MaskedArray.__sub__

Python | Numpy MaskedArray.__sub__

numpy.ma.MaskedArray class is a subclass of ndarray designed to manipulate numerical arrays with missing data. With the help of Numpy MaskedArray.__sub__ we can subtract a particular value that is provided as a parameter in the MaskedArray.__sub__() method. Value will be subtracted from each and every element in a numpy array.

Syntax: numpy.MaskedArray.__sub__

Return: Subtract others from self, 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.__sub__(). Remember one thing it wouldn’t work for double type values.




# import the important module in python 
import numpy as np 
  
# make an array with numpy 
gfg = np.ma.array([11, 22, 23, 24, 25]) 
  
# applying MaskedArray.__sub__() method 
print(gfg.__sub__(5)) 


Output:

[ 6 17 18 19 20]

 
Example #2:




# import the important module in 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.__sub__() method 
print(gfg.__sub__(5)) 


Output:

[[16 17 18 19 20]
 [21 20 19 18 17]]
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32514 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
6892 POSTS0 COMMENTS
Nicole Veronica
12012 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12107 POSTS0 COMMENTS
Shaida Kate Naidoo
7016 POSTS0 COMMENTS
Ted Musemwa
7262 POSTS0 COMMENTS
Thapelo Manthata
6975 POSTS0 COMMENTS
Umr Jansen
6963 POSTS0 COMMENTS