cf.Data.isclose

Data.isclose(y, rtol=None, atol=None)[source]

Return where data are element-wise equal within a tolerance.

Two real numbers x and y are considered equal if |x-y|<=atol+rtol|y|, where atol (the tolerance on absolute differences) and rtol (the tolerance on relative differences) are positive, typically very small numbers. See the atol and rtol parameters.

For numeric data arrays, d.isclose(e, rtol, atol) is equivalent to abs(d - e) <= atol + rtol*abs(e), otherwise it is equivalent to d == e.

Parameters
y: data_like

The array to compare.

atol: float, optional

The absolute tolerance for all numerical comparisons. By default the value returned by the atol function is used.

rtol: float, optional

The relative tolerance for all numerical comparisons. By default the value returned by the rtol function is used.

Returns
bool

A boolean array of where the data are close to y.

Examples

>>> d = cf.Data([1000, 2500], 'metre')
>>> e = cf.Data([1, 2.5], 'km')
>>> print(d.isclose(e).array)
[ True  True]
>>> d = cf.Data(['ab', 'cdef'])
>>> print(d.isclose([[['ab', 'cdef']]]).array)
[[[ True  True]]]
>>> d = cf.Data([[1000, 2500], [1000, 2500]], 'metre')
>>> e = cf.Data([1, 2.5], 'km')
>>> print(d.isclose(e).array)
[[ True  True]
 [ True  True]]
>>> d = cf.Data([1, 1, 1], 's')
>>> print(d.isclose(1).array)
[ True  True  True]