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)
| 834 | |
| 835 | |
| 836 | def assert_array_almost_equal(x, y, decimal=6, err_msg="", verbose=True): |
| 837 | """ |
| 838 | Raises an AssertionError if two objects are not equal up to desired |
| 839 | precision. |
| 840 | |
| 841 | .. note:: It is recommended to use one of `assert_allclose`, |
| 842 | `assert_array_almost_equal_nulp` or `assert_array_max_ulp` |
| 843 | instead of this function for more consistent floating point |
| 844 | comparisons. |
| 845 | |
| 846 | The test verifies identical shapes and that the elements of ``actual`` and |
| 847 | ``desired`` satisfy. |
| 848 | |
| 849 | ``abs(desired-actual) < 1.5 * 10**(-decimal)`` |
| 850 | |
| 851 | That is a looser test than originally documented, but agrees with what the |
| 852 | actual implementation did up to rounding vagaries. An exception is raised |
| 853 | at shape mismatch or conflicting values. In contrast to the standard usage |
| 854 | in numpy, NaNs are compared like numbers, no assertion is raised if both |
| 855 | objects have NaNs in the same positions. |
| 856 | |
| 857 | Parameters |
| 858 | ---------- |
| 859 | x : array_like |
| 860 | The actual object to check. |
| 861 | y : array_like |
| 862 | The desired, expected object. |
| 863 | decimal : int, optional |
| 864 | Desired precision, default is 6. |
| 865 | err_msg : str, optional |
| 866 | The error message to be printed in case of failure. |
| 867 | verbose : bool, optional |
| 868 | If True, the conflicting values are appended to the error message. |
| 869 | |
| 870 | Raises |
| 871 | ------ |
| 872 | AssertionError |
| 873 | If actual and desired are not equal up to specified precision. |
| 874 | |
| 875 | See Also |
| 876 | -------- |
| 877 | assert_allclose: Compare two array_like objects for equality with desired |
| 878 | relative and/or absolute precision. |
| 879 | assert_array_almost_equal_nulp, assert_array_max_ulp, assert_equal |
| 880 | |
| 881 | Examples |
| 882 | -------- |
| 883 | the first assert does not raise an exception |
| 884 | |
| 885 | >>> np.testing.assert_array_almost_equal([1.0,2.333,np.nan], |
| 886 | ... [1.0,2.333,np.nan]) |
| 887 | |
| 888 | >>> np.testing.assert_array_almost_equal([1.0,2.33333,np.nan], |
| 889 | ... [1.0,2.33339,np.nan], decimal=5) |
| 890 | Traceback (most recent call last): |
| 891 | ... |
| 892 | AssertionError: |
| 893 | Arrays are not almost equal to 5 decimals |
searching dependent graphs…