numpy.ma.MaskedArray.filled¶
-
MaskedArray.
filled
(fill_value=None)[source]¶ 返回self的副本,掩码值填充给定值。但是,如果没有要填充的掩码值,则self将作为ndarray返回。
参数: fill_value:标量,可选
用于无效条目的值(默认值为None)。如果为“无”,则使用数组的
fill_value
属性。返回: filled_array:ndarray
A copy of
self
with invalid entries replaced by fill_value (be it the function argument or the attribute ofself
), orself
itself as an ndarray if there are no invalid entries to be replaced.笔记
结果是不 a MaskedArray!
例子
>>> x = np.ma.array([1,2,3,4,5], mask=[0,0,1,0,1], fill_value=-999) >>> x.filled() array([1, 2, -999, 4, -999]) >>> type(x.filled()) <type 'numpy.ndarray'>
子类保留。这意味着如果掩码数组的数据部分是一个矩阵,
filled
返回一个矩阵:>>> x = np.ma.array(np.matrix([[1, 2], [3, 4]]), mask=[[0, 1], [1, 0]]) >>> x.filled() matrix([[ 1, 999999], [999999, 4]])