Thursday, October 16, 2025
HomeLanguagesnumpy.ma.fix_invalid() function | Python

numpy.ma.fix_invalid() function | Python

numpy.ma.fix_invalid() function return input with invalid data masked and replaced by a fill value. Where invalid data means values of nan, inf, etc.

Syntax : numpy.ma.fix_invalid(arr, mask = False, copy = True, fill_value = None)

Parameter :
arr : [array_like] Input array.
mask : [sequence, 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 use a copy of a (True) or to fix a in place (False). Default is True.
fill_value : [scalar, optional] Value used for fixing invalid data. Default is None, in which case the arr.fill_value is used.

Return : [MaskedArray] The input array with invalid entries fixed.

Code #1 :




# Python program explaining
# numpy.ma.fix_invalid() function
  
# importing numpy as geek 
import numpy as geek 
   
arr = geek.ma.array([1., -1, geek.nan, geek.inf],
                              mask =[1] + [0]*3)
  
gfg = geek.ma.fix_invalid(arr)
  
print (gfg)


Output :

[-- -1.0 -- --]

 
Code #2 :




# Python program explaining
# numpy.ma.fix_invalid() function
  
# importing numpy as geek 
import numpy as geek 
   
arr = geek.ma.array([1., -1, geek.nan,
                    geek.inf, -1, geek.nan],
                          mask =[1] + [0]*5)
  
gfg = geek.ma.fix_invalid(arr)
  
print (gfg)


Output :

[-- -1.0 -- -- -1.0 --]
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