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
(x, y, err_msg="", verbose=True, *, strict=False)
| 728 | |
| 729 | |
| 730 | def assert_array_equal(x, y, err_msg="", verbose=True, *, strict=False): |
| 731 | """ |
| 732 | Raises an AssertionError if two array_like objects are not equal. |
| 733 | |
| 734 | Given two array_like objects, check that the shape is equal and all |
| 735 | elements of these objects are equal (but see the Notes for the special |
| 736 | handling of a scalar). An exception is raised at shape mismatch or |
| 737 | conflicting values. In contrast to the standard usage in numpy, NaNs |
| 738 | are compared like numbers, no assertion is raised if both objects have |
| 739 | NaNs in the same positions. |
| 740 | |
| 741 | The usual caution for verifying equality with floating point numbers is |
| 742 | advised. |
| 743 | |
| 744 | Parameters |
| 745 | ---------- |
| 746 | x : array_like |
| 747 | The actual object to check. |
| 748 | y : array_like |
| 749 | The desired, expected object. |
| 750 | err_msg : str, optional |
| 751 | The error message to be printed in case of failure. |
| 752 | verbose : bool, optional |
| 753 | If True, the conflicting values are appended to the error message. |
| 754 | strict : bool, optional |
| 755 | If True, raise an AssertionError when either the shape or the data |
| 756 | type of the array_like objects does not match. The special |
| 757 | handling for scalars mentioned in the Notes section is disabled. |
| 758 | |
| 759 | Raises |
| 760 | ------ |
| 761 | AssertionError |
| 762 | If actual and desired objects are not equal. |
| 763 | |
| 764 | See Also |
| 765 | -------- |
| 766 | assert_allclose: Compare two array_like objects for equality with desired |
| 767 | relative and/or absolute precision. |
| 768 | assert_array_almost_equal_nulp, assert_array_max_ulp, assert_equal |
| 769 | |
| 770 | Notes |
| 771 | ----- |
| 772 | When one of `x` and `y` is a scalar and the other is array_like, the |
| 773 | function checks that each element of the array_like object is equal to |
| 774 | the scalar. This behaviour can be disabled with the `strict` parameter. |
| 775 | |
| 776 | Examples |
| 777 | -------- |
| 778 | The first assert does not raise an exception: |
| 779 | |
| 780 | >>> np.testing.assert_array_equal([1.0,2.33333,np.nan], |
| 781 | ... [np.exp(0),2.33333, np.nan]) |
| 782 | |
| 783 | Use `assert_allclose` or one of the nulp (number of floating point values) |
| 784 | functions for these cases instead: |
| 785 | |
| 786 | >>> np.testing.assert_allclose([1.0,np.pi,np.nan], |
| 787 | ... [1, np.sqrt(np.pi)**2, np.nan], |
searching dependent graphs…