numpy.ma.masked_invalid#

ma.masked_invalid(a,copy=True)[source]#

Mask an array where invalid values occur (NaNs or infs).

This function is a shortcut tomasked_where, withcondition = ~(np.isfinite(a)). Any pre-existing mask is conserved.Only applies to arrays with a dtype where NaNs or infs make sense(i.e. floating point types), but accepts any array_like object.

See also

masked_where

Mask where a condition is met.

Examples

>>>importnumpyasnp>>>importnumpy.maasma>>>a=np.arange(5,dtype=float)>>>a[2]=np.nan>>>a[3]=np.inf>>>aarray([ 0.,  1., nan, inf,  4.])>>>ma.masked_invalid(a)masked_array(data=[0.0, 1.0, --, --, 4.0],             mask=[False, False,  True,  True, False],       fill_value=1e+20)
On this page