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)
| 924 | |
| 925 | @np._no_nep50_warning() |
| 926 | def 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 |