Friday, September 19, 2025
HomeLanguagesnumpy.ma.masked_values() function | Python

numpy.ma.masked_values() function | Python

numpy.ma.masked_values() function return a MaskedArray, masked where the data in array arr are approximately equal to value, determined using isclose. The default tolerances for masked_values are the same as those for isclose.

Syntax : numpy.ma.masked_values(arr, value, rtol = 1e-05, atol = 1e-08, copy = True, shrink = True)

Parameter :
arr : [array_like] Array to mask.
value : [float] Masking value.
rtol, atol : [float, optional] Must be convertible to an array of booleans with the same shape as data. True indicates a masked data.
copy : [bool, optional] Whether to return a copy of arr.
shrink : [bool, optional] Whether to collapse a mask full of False to nomask.

Return : [MaskedArray] The result of masking arr where approximately equal to value.

Code #1 :




# Python program explaining
# numpy.ma.masked_values() function
  
# importing numpy as geek 
# and numpy.ma module as ma 
import numpy as geek 
import numpy.ma as ma
   
arr = geek.array([1, 1.5, 2, 1.5, 3])
  
gfg = ma.masked_values(arr, 1.5)
  
print (gfg)


Output :

[1.0 -- 2.0 -- 3.0]

 
Code #2 :




# Python program explaining
# numpy.ma.masked_values() function
  
# importing numpy as geek 
# and numpy.ma module as ma 
import numpy as geek 
import numpy.ma as ma
   
arr = geek.array([1, 2, 3, 4, 5, 6])
  
gfg = ma.masked_values(arr, 4)
  
print (gfg)


Output :

[1 2 3 -- 5 6]
Dominic
Dominichttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Dominic
32301 POSTS0 COMMENTS
Milvus
84 POSTS0 COMMENTS
Nango Kala
6666 POSTS0 COMMENTS
Nicole Veronica
11840 POSTS0 COMMENTS
Nokonwaba Nkukhwana
11898 POSTS0 COMMENTS
Shaida Kate Naidoo
6781 POSTS0 COMMENTS
Ted Musemwa
7056 POSTS0 COMMENTS
Thapelo Manthata
6739 POSTS0 COMMENTS
Umr Jansen
6744 POSTS0 COMMENTS