cf.Data.mask_invalid

Data.mask_invalid(inplace=False, i=False)[source]

Mask the array where invalid values occur (NaN or inf).

Note that:

  • Invalid values in the results of arithmetic operations may only occur if the raising of FloatingPointError exceptions has been suppressed by cf.Data.seterr.

  • If the raising of FloatingPointError exceptions has been allowed then invalid values in the results of arithmetic operations it is possible for them to be automatically converted to masked values, depending on the setting of cf.Data.mask_fpe. In this case, such automatic conversion might be faster than calling mask_invalid.

Parameters
inplace: bool, optional

If True then do the operation in-place and return None.

i: deprecated at version 3.0.0

Use the inplace parameter instead.

Returns

Data or None

Examples:

>>> d = cf.Data([0., 1])
>>> e = cf.Data([1., 2])
>>> old = cf.Data.seterr('ignore')
>>> f = e/d
>>> f
<CF Data: [inf, 2.0] >
>>> f.mask_invalid()
<CF Data: [--, 2.0] >
>>> f=e**12345
>>> f
<CF Data: [1.0, inf] >
>>> f.mask_invalid()
<CF Data: [1.0, --] >
>>> old = cf.Data.seterr('raise')
>>> old = cf.Data.mask_fpe(True)
>>> e/d
<CF Data: [--, 2.0] >
>>> e**12345
<CF Data: [1.0, --] >