numpy.ma.filled#

ma.filled(a,fill_value=None)[source]#

Return input as anndarray, with masked values replaced byfill_value.

Ifa is not aMaskedArray,a itself is returned.Ifa is aMaskedArray with no masked values, thena.data isreturned.Ifa is aMaskedArray andfill_value is None,fill_value is set toa.fill_value.

Parameters:
aMaskedArray or array_like

An input object.

fill_valuearray_like, optional.

Can be scalar or non-scalar. If non-scalar, theresulting filled array should be broadcastableover input array. Default is None.

Returns:
andarray

The filled array.

See also

compressed

Examples

>>>importnumpyasnp>>>importnumpy.maasma>>>x=ma.array(np.arange(9).reshape(3,3),mask=[[1,0,0],...[1,0,0],...[0,0,0]])>>>x.filled()array([[999999,      1,      2],       [999999,      4,      5],       [     6,      7,      8]])>>>x.filled(fill_value=333)array([[333,   1,   2],       [333,   4,   5],       [  6,   7,   8]])>>>x.filled(fill_value=np.arange(3))array([[0, 1, 2],       [0, 4, 5],       [6, 7, 8]])
On this page