cf.Data.mask_invalid

Data.mask_invalid(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:
i : bool, optional

If True then update the data array in place. By default a new data array is created.

Returns:

out : cf.Data

Examples 2:
>>> 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, --] >