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

Whether an array is element-wise equal within a tolerance.

Return True if the data is broadcastable to array y and 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.

Parameters:
y: data_like

The data to compare.

rtol: number, optional

The tolerance on relative differences between real numbers. The default value is set by the cf.rtol function.

atol: number, optional

The tolerance on absolute differences between real numbers. The default value is set by the cf.atol function.

Returns:
Data

A scalar boolean array that is True if the two arrays are equal within the given tolerance, or False otherwise.

Examples

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