Raises an AssertionError if two array_like objects are not equal. Given two array_like objects, check that the shape is equal and all elements of these objects are equal (but see the Notes for the special handling of a scalar). An exception is raised at shape mismatch or confli
(actual, desired, err_msg='', verbose=True, *,
strict=False)
| 997 | |
| 998 | |
| 999 | def assert_array_equal(actual, desired, err_msg='', verbose=True, *, |
| 1000 | strict=False): |
| 1001 | """ |
| 1002 | Raises an AssertionError if two array_like objects are not equal. |
| 1003 | |
| 1004 | Given two array_like objects, check that the shape is equal and all |
| 1005 | elements of these objects are equal (but see the Notes for the special |
| 1006 | handling of a scalar). An exception is raised at shape mismatch or |
| 1007 | conflicting values. In contrast to the standard usage in numpy, NaNs |
| 1008 | are compared like numbers, no assertion is raised if both objects have |
| 1009 | NaNs in the same positions. |
| 1010 | |
| 1011 | The usual caution for verifying equality with floating point numbers is |
| 1012 | advised. |
| 1013 | |
| 1014 | .. note:: When either `actual` or `desired` is already an instance of |
| 1015 | `numpy.ndarray` and `desired` is not a ``dict``, the behavior of |
| 1016 | ``assert_equal(actual, desired)`` is identical to the behavior of this |
| 1017 | function. Otherwise, this function performs `np.asanyarray` on the |
| 1018 | inputs before comparison, whereas `assert_equal` defines special |
| 1019 | comparison rules for common Python types. For example, only |
| 1020 | `assert_equal` can be used to compare nested Python lists. In new code, |
| 1021 | consider using only `assert_equal`, explicitly converting either |
| 1022 | `actual` or `desired` to arrays if the behavior of `assert_array_equal` |
| 1023 | is desired. |
| 1024 | |
| 1025 | Parameters |
| 1026 | ---------- |
| 1027 | actual : array_like |
| 1028 | The actual object to check. |
| 1029 | desired : array_like |
| 1030 | The desired, expected object. |
| 1031 | err_msg : str, optional |
| 1032 | The error message to be printed in case of failure. |
| 1033 | verbose : bool, optional |
| 1034 | If True, the conflicting values are appended to the error message. |
| 1035 | strict : bool, optional |
| 1036 | If True, raise an AssertionError when either the shape or the data |
| 1037 | type of the array_like objects does not match. The special |
| 1038 | handling for scalars mentioned in the Notes section is disabled. |
| 1039 | |
| 1040 | .. versionadded:: 1.24.0 |
| 1041 | |
| 1042 | Raises |
| 1043 | ------ |
| 1044 | AssertionError |
| 1045 | If actual and desired objects are not equal. |
| 1046 | |
| 1047 | See Also |
| 1048 | -------- |
| 1049 | assert_allclose: Compare two array_like objects for equality with desired |
| 1050 | relative and/or absolute precision. |
| 1051 | assert_array_almost_equal_nulp, assert_array_max_ulp, assert_equal |
| 1052 | |
| 1053 | Notes |
| 1054 | ----- |
| 1055 | When one of `actual` and `desired` is a scalar and the other is array_like, the |
| 1056 | function checks that each element of the array_like is equal to the scalar. |
searching dependent graphs…