numpy.testing.assert_allclose

numpy.testing.assert_allclose(actual, desired, rtol=1e-07, atol=0, equal_nan=True, err_msg='', verbose=True) [source]

Raises an AssertionError if two objects are not equal up to desired tolerance.

The test is equivalent to allclose(actual, desired, rtol, atol) (note that allclose has different default values). It compares the difference between actual and desired to atol + rtol * abs(desired).

New in version 1.5.0.

Parameters
actualarray_like

Array obtained.

desiredarray_like

Array desired.

rtolfloat, optional

Relative tolerance.

atolfloat, optional

Absolute tolerance.

equal_nanbool, optional.

If True, NaNs will compare equal.

err_msgstr, optional

The error message to be printed in case of failure.

verbosebool, optional

If True, the conflicting values are appended to the error message.

Raises
AssertionError

If actual and desired are not equal up to specified precision.

Examples

>>> x = [1e-5, 1e-3, 1e-1]
>>> y = np.arccos(np.cos(x))
>>> np.testing.assert_allclose(x, y, rtol=1e-5, atol=0)

© 2005–2020 NumPy Developers
Licensed under the 3-clause BSD License.
https://numpy.org/doc/1.19/reference/generated/numpy.testing.assert_allclose.html