cf.Data.mask_fpe¶
-
static
Data.
mask_fpe
(*arg)[source]¶ Masking of floating-point errors in the results of arithmetic operations.
If masking is allowed then only floating-point errors which would otherwise be raised as
FloatingPointError
exceptions are masked. WhetherFloatingPointError
exceptions may be raised is determined bycf.Data.seterr
.If called without an argument then the current behaviour is returned.
Note that if the raising of
FloatingPointError
exceptions has suppressed then invalid values in the results of arithmetic operations may be subsequently converted to masked values with themask_invalid
method.See also
Parameters: - arg : bool, optional
The new behaviour. True means that
FloatingPointError
exceptions are suppressed and replaced with masked values. False means thatFloatingPointError
exceptions are raised. The default is not to change the current behaviour.
Returns: - out : bool
The behaviour prior to the change, or the current behaviour if no new value was specified.
Examples: >>> d = cf.Data([0., 1]) >>> e = cf.Data([1., 2])
>>> old = cf.Data.mask_fpe(False) >>> old = cf.Data.seterr('raise') >>> e/d FloatingPointError: divide by zero encountered in divide >>> e**123456 FloatingPointError: overflow encountered in power
>>> old = cf.Data.mask_fpe(True) >>> old = cf.Data.seterr('raise') >>> e/d <CF Data: [--, 2.0] > >>> e**123456 <CF Data: [1.0, --] >
>>> old = cf.Data.mask_fpe(True) >>> old = cf.Data.seterr('ignore') >>> e/d <CF Data: [inf, 2.0] > >>> e**123456 <CF Data: [1.0, inf] >