📜  numpy.ma.filled()函数– Python

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

numpy.ma.filled()函数– Python

numpy.ma.filled()函数将输入作为数组返回,其中掩码数据替换为填充值。如果 arr 不是 MaskedArray,则返回 arr 本身。如果 arr 是 MaskedArray 且 fill_value 为 None,则 fill_value 设置为 arr.fill_value。

代码#1:

# Python program explaining
# numpy.ma.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(geek.arange(4).reshape(2, 2),
                         mask =[[1, 0], [0, 1]])
  
gfg = arr.filled()
  
print (gfg)

输出 :

[[999999      1]
 [     2 999999]]


代码#2:

# Python program explaining
# numpy.ma.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(geek.arange(9).reshape(3, 3), 
          mask =[[1, 0, 0], [1, 0, 0], [0, 0, 0]])
  
gfg = arr.filled()
  
print (gfg)

输出 :

[[999999      1      2]
 [999999      4      5]
 [     6      7      8]]