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

Function assert_array_equal

numpy/testing/_private/utils.py:808–922  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

806
807
808def assert_array_equal(x, y, err_msg='', verbose=True, *, strict=False):
809 """
810 Raises an AssertionError if two array_like objects are not equal.
811
812 Given two array_like objects, check that the shape is equal and all
813 elements of these objects are equal (but see the Notes for the special
814 handling of a scalar). An exception is raised at shape mismatch or
815 conflicting values. In contrast to the standard usage in numpy, NaNs
816 are compared like numbers, no assertion is raised if both objects have
817 NaNs in the same positions.
818
819 The usual caution for verifying equality with floating point numbers is
820 advised.
821
822 Parameters
823 ----------
824 x : array_like
825 The actual object to check.
826 y : array_like
827 The desired, expected object.
828 err_msg : str, optional
829 The error message to be printed in case of failure.
830 verbose : bool, optional
831 If True, the conflicting values are appended to the error message.
832 strict : bool, optional
833 If True, raise an AssertionError when either the shape or the data
834 type of the array_like objects does not match. The special
835 handling for scalars mentioned in the Notes section is disabled.
836
837 .. versionadded:: 1.24.0
838
839 Raises
840 ------
841 AssertionError
842 If actual and desired objects are not equal.
843
844 See Also
845 --------
846 assert_allclose: Compare two array_like objects for equality with desired
847 relative and/or absolute precision.
848 assert_array_almost_equal_nulp, assert_array_max_ulp, assert_equal
849
850 Notes
851 -----
852 When one of `x` and `y` is a scalar and the other is array_like, the
853 function checks that each element of the array_like object is equal to
854 the scalar. This behaviour can be disabled with the `strict` parameter.
855
856 Examples
857 --------
858 The first assert does not raise an exception:
859
860 >>> np.testing.assert_array_equal([1.0,2.33333,np.nan],
861 ... [np.exp(0),2.33333, np.nan])
862
863 Assert fails with numerical imprecision with floats:
864
865 >>> np.testing.assert_array_equal([1.0,np.pi,np.nan],

Calls 1

assert_array_compareFunction · 0.70