numpy.ma.MaskedArray.get_fill_value#

method

ma.MaskedArray.get_fill_value()[source]#

The default value used to replace masked entries when filling the array.

This scalar is used by filled when no explicit replacement value is provided. Setting fill_value does not change the underlying data or the mask. Setting it to None restores the default value for the array’s data type.

See also

filled

Return an ndarray with masked entries replaced.

set_fill_value

Set the filling value of a masked array.

Examples

>>> import numpy as np
>>> x = np.ma.array([10, 20, 30], mask=[False, True, False],
...                 fill_value=-999)
>>> x.filled()
array([  10, -999,   30])
>>> x.filled(fill_value=0)
array([10,  0, 30])
>>> x.data
array([10, 20, 30])
>>> for dt in [np.int32, np.int64, np.float64, np.complex128]:
...     np.ma.array([0, 1], dtype=dt).get_fill_value()
...
np.int64(999999)
np.int64(999999)
np.float64(1e+20)
np.complex128(1e+20+0j)
>>> x = np.ma.array([0, 1.], fill_value=-np.inf)
>>> x.fill_value
np.float64(-inf)
>>> x.fill_value = np.pi
>>> x.fill_value
np.float64(3.141592653589793)

Reset to default:

>>> x.fill_value = None
>>> x.fill_value
np.float64(1e+20)