numpy.ma.filled()函数– Python
numpy.ma.filled()
函数将输入作为数组返回,其中掩码数据替换为填充值。如果 arr 不是 MaskedArray,则返回 arr 本身。如果 arr 是 MaskedArray 且 fill_value 为 None,则 fill_value 设置为 arr.fill_value。
Syntax : numpy.ma.filled(arr, fill_value = None)
Parameters :
arr : [MaskedArray or array_like] An input object.
fill_value : [scalar, optional] Filling value. Default is None.
Return : [ndarray] The filled array.
代码#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]]