这是功能还是错误?有人可以向我解释 numpy masked_array 的这种行为吗?应用 sum 操作后似乎更改了 fill_value,如果您打算使用填充结果,这会令人困惑。
data=ones((5,5))
m=zeros((5,5),dtype=bool)
"""Mask out row 3"""
m[3,:]=True
arr=ma.masked_array(data,mask=m,fill_value=nan)
print arr
print 'Fill value:', arr.fill_value
print arr.filled()
farr=arr.sum(axis=1)
print farr
print 'Fill value:', farr.fill_value
print farr.filled()
"""I was expecting this"""
print nansum(arr.filled(),axis=1)
打印输出:
[[1.0 1.0 1.0 1.0 1.0]
[1.0 1.0 1.0 1.0 1.0]
[1.0 1.0 1.0 1.0 1.0]
[-- -- -- -- --]
[1.0 1.0 1.0 1.0 1.0]]
Fill value: nan
[[ 1. 1. 1. 1. 1.]
[ 1. 1. 1. 1. 1.]
[ 1. 1. 1. 1. 1.]
[ nan nan nan nan nan]
[ 1. 1. 1. 1. 1.]]
[5.0 5.0 5.0 -- 5.0]
Fill value: 1e+20
[ 5.00000000e+00 5.00000000e+00 5.00000000e+00 1.00000000e+20
5.00000000e+00]
[ 5. 5. 5. nan 5.]