MCPcopy Create free account
hub / github.com/numpy/numpy / assert_array_almost_equal

Function assert_array_almost_equal

numpy/testing/_private/utils.py:926–1036  ·  view source on GitHub ↗

Raises an AssertionError if two objects are not equal up to desired precision. .. note:: It is recommended to use one of `assert_allclose`, `assert_array_almost_equal_nulp` or `assert_array_max_ulp` instead of this function for more consistent floating point

(x, y, decimal=6, err_msg='', verbose=True)

Source from the content-addressed store, hash-verified

924
925@np._no_nep50_warning()
926def assert_array_almost_equal(x, y, decimal=6, err_msg='', verbose=True):
927 """
928 Raises an AssertionError if two objects are not equal up to desired
929 precision.
930
931 .. note:: It is recommended to use one of `assert_allclose`,
932 `assert_array_almost_equal_nulp` or `assert_array_max_ulp`
933 instead of this function for more consistent floating point
934 comparisons.
935
936 The test verifies identical shapes and that the elements of ``actual`` and
937 ``desired`` satisfy.
938
939 ``abs(desired-actual) < 1.5 * 10**(-decimal)``
940
941 That is a looser test than originally documented, but agrees with what the
942 actual implementation did up to rounding vagaries. An exception is raised
943 at shape mismatch or conflicting values. In contrast to the standard usage
944 in numpy, NaNs are compared like numbers, no assertion is raised if both
945 objects have NaNs in the same positions.
946
947 Parameters
948 ----------
949 x : array_like
950 The actual object to check.
951 y : array_like
952 The desired, expected object.
953 decimal : int, optional
954 Desired precision, default is 6.
955 err_msg : str, optional
956 The error message to be printed in case of failure.
957 verbose : bool, optional
958 If True, the conflicting values are appended to the error message.
959
960 Raises
961 ------
962 AssertionError
963 If actual and desired are not equal up to specified precision.
964
965 See Also
966 --------
967 assert_allclose: Compare two array_like objects for equality with desired
968 relative and/or absolute precision.
969 assert_array_almost_equal_nulp, assert_array_max_ulp, assert_equal
970
971 Examples
972 --------
973 the first assert does not raise an exception
974
975 >>> np.testing.assert_array_almost_equal([1.0,2.333,np.nan],
976 ... [1.0,2.333,np.nan])
977
978 >>> np.testing.assert_array_almost_equal([1.0,2.33333,np.nan],
979 ... [1.0,2.33339,np.nan], decimal=5)
980 Traceback (most recent call last):
981 ...
982 AssertionError:
983 Arrays are not almost equal to 5 decimals

Callers 15

test_randMethod · 0.90
test_rand_singletonMethod · 0.90
test_randnMethod · 0.90
test_random_sampleMethod · 0.90
test_betaMethod · 0.90
test_chisquareMethod · 0.90
test_dirichletMethod · 0.90
test_exponentialMethod · 0.90
test_fMethod · 0.90
test_gammaMethod · 0.90
test_gumbelMethod · 0.90

Calls 1

assert_array_compareFunction · 0.70

Tested by 15

test_randMethod · 0.72
test_rand_singletonMethod · 0.72
test_randnMethod · 0.72
test_random_sampleMethod · 0.72
test_betaMethod · 0.72
test_chisquareMethod · 0.72
test_dirichletMethod · 0.72
test_exponentialMethod · 0.72
test_fMethod · 0.72
test_gammaMethod · 0.72
test_gumbelMethod · 0.72