📜  numpy.ma.fix_invalid()函数| Python

📅  最后修改于: 2022-05-13 01:54:27.564000             🧑  作者: Mango

numpy.ma.fix_invalid()函数| Python

numpy.ma.fix_invalid()函数返回输入,其中无效数据被屏蔽并替换为填充值。其中无效数据表示 nan、inf 等的值。

代码#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)

输出 :

[-- -1.0 -- --]


代码#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)

输出 :

[-- -1.0 -- -- -1.0 --]