bundles / numpy 2.4.3 / numpy / ma / core / MaskedArray / filled
function
numpy.ma.core:MaskedArray.filled
source: /numpy/ma/core.py:3856
Signature
def filled(self, fill_value = None)Summary
Return a copy of self, with masked values filled with a given value. However, if there are no masked values to fill, self will be returned instead as an ndarray.
Parameters
fill_value: array_like, optionalThe value to use for invalid entries. Can be scalar or non-scalar. If non-scalar, the resulting ndarray must be broadcastable over input array. Default is None, in which case, the
fill_valueattribute of the array is used instead.
Returns
filled_array: ndarrayA copy of
selfwith invalid entries replaced by fill_value (be it the function argument or the attribute ofself), orselfitself as an ndarray if there are no invalid entries to be replaced.
Notes
The result is not a MaskedArray!
Examples
import numpy as np x = np.ma.array([1,2,3,4,5], mask=[0,0,1,0,1], fill_value=-999) x.filled() x.filled(fill_value=1000) type(x.filled())Subclassing is preserved. This means that if, e.g., the data part of the masked array is a recarray, `filled` returns a recarray:
x = np.array([(-1, 2), (-3, 4)], dtype='i8,i8').view(np.recarray) m = np.ma.array(x, mask=[(True, False), (False, True)]) m.filled()
Aliases
numpy.ma.MaskedArray.filled