SciPy

This is documentation for an old release of NumPy (version 1.8.0). Read this page in the documentation of the latest stable release (version > 1.17).

numpy.testing.assert_allclose

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

Raise an assertion if two objects are not equal up to desired tolerance.

The test is equivalent to allclose(actual, desired, rtol, atol). It compares the difference between actual and desired to atol + rtol * abs(desired).

Parameters :

actual : array_like

Array obtained.

desired : array_like

Array desired.

rtol : float, optional

Relative tolerance.

atol : float, optional

Absolute tolerance.

err_msg : str, optional

The error message to be printed in case of failure.

verbose : bool, 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))
>>> assert_allclose(x, y, rtol=1e-5, atol=0)