SciPy, mask=False, copy=True, fill_value=None)[source]

Return input with invalid data masked and replaced by a fill value.

Invalid data means values of nan, inf, etc.


a : array_like

Input array, a (subclass of) ndarray.

mask : sequence, optional

Mask. Must be convertible to an array of booleans with the same shape as data. True indicates a masked (i.e. invalid) data.

copy : bool, optional

Whether to use a copy of a (True) or to fix a in place (False). Default is True.

fill_value : scalar, optional

Value used for fixing invalid data. Default is None, in which case the a.fill_value is used.


b : MaskedArray

The input array with invalid entries fixed.


A copy is performed by default.


>>> x =[1., -1, np.nan, np.inf], mask=[1] + [0]*3)
>>> x
masked_array(data = [-- -1.0 nan inf],
             mask = [ True False False False],
       fill_value = 1e+20)
masked_array(data = [-- -1.0 -- --],
             mask = [ True False  True  True],
       fill_value = 1e+20)
>>> fixed =
array([  1.00000000e+00,  -1.00000000e+00,   1.00000000e+20,
array([  1.,  -1.,  NaN,  Inf])

Previous topic

Next topic