Friday, October 24, 2025
HomeLanguagesnumpy.ma.make_mask() function | Python

numpy.ma.make_mask() function | Python

numpy.ma.make_mask() function is used to create a boolean mask from an array. 
This function can accept any sequence that is convertible to integers, or nomask. It does not require that contents must be 0s and 1s, values of 0 are interpreted as False, everything else as True. Return m as a boolean mask. 
 

Syntax : numpy.ma.make_mask(m, copy = False, shrink = True, dtype = bool )
Parameters : 
arr : [ array_like] Potential mask. 
copy : [bool, optional] Whether to return a copy of m (True) or m itself (False). 
shrink : [bool, optional] Whether to shrink m to nomask if all its values are False. 
dtype : [dtype, optional] Data-type of the output mask. By default, the output mask has a dtype of MaskType (bool).
Return : [ndarray] A boolean mask derived from m. 
 

Code #1 : 
 

Python3




# Python program explaining
# numpy.ma.make_mask() function
 
# importing numpy as geek 
# and numpy.ma module as ma
import numpy as geek
import numpy.ma as ma
 
m = [1, 1, 0, 1]
 
gfg = ma.make_mask(m)
 
print (gfg)


Output : 
 

[ True  True False  True]

  
Code #2 : 
 

Python3




# Python program explaining
# numpy.ma.make_mask() function
 
# importing numpy as geek 
# and numpy.ma module as ma
import numpy as geek
import numpy.ma as ma
 
m = [2, -3, 0, 1]
 
gfg = ma.make_mask(m)
 
print (gfg)


Output : 
 

[ True  True False  True]

  
Code #3 : 
 

Python3




# Python program explaining
# numpy.ma.make_mask() function
 
# importing numpy as geek 
# and numpy.ma module as ma
import numpy as geek
import numpy.ma as ma
 
m = [True, True, True, False]
 
gfg = ma.make_mask(m)
 
print (gfg)


Output : 
 

[ True  True  True False]

 

Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32361 POSTS0 COMMENTS
Milvus
88 POSTS0 COMMENTS
Nango Kala
6728 POSTS0 COMMENTS
Nicole Veronica
11892 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11954 POSTS0 COMMENTS
Shaida Kate Naidoo
6852 POSTS0 COMMENTS
Ted Musemwa
7113 POSTS0 COMMENTS
Thapelo Manthata
6805 POSTS0 COMMENTS
Umr Jansen
6801 POSTS0 COMMENTS