📜  Numpy MaskedArray.filled() 方法 – Python

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

Numpy MaskedArray.filled() 方法 – Python

numpy.MaskedArray.filled()函数返回一个 self 的副本,掩码值填充给定值。但是,如果没有要填充的掩码值,则 self 将作为 ndarray 返回。

代码#1:

# Python program explaining
# numpy.MaskedArray.filled() function
  
# importing numpy as geek  
# and numpy.ma module as ma 
import numpy as geek 
import numpy.ma as ma
  
arr = geek.ma.array([2, 4, 6, 8, 10], mask =[0, 0, 1, 0, 1],
                                          fill_value = -999)
gfg = arr.filled()
  
print(gfg)

输出 :

[   2    4 -999    8 -999]


代码#2:

# Python program explaining
# numpy.MaskedArray.filled() function
  
# importing numpy as geek  
# and numpy.ma module as ma 
import numpy as geek 
import numpy.ma as ma
  
arr = geek.ma.array([1, 2, 3, 4, 5], mask =[1, 0, 1, 0, 0], 
                                         fill_value = -999)
gfg = arr.filled()
  
print(gfg)

输出 :

[-999    2 -999    4    5]