Raise an assertion 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. An exception is raised at shape mismatch or conflicting values. In contrast to the standard usage in numpy, NaNs are compared like numbers, no assertion is raised if both objects have NaNs in the same positions.
The usual caution for verifying equality with floating point numbers is advised.
Parameters: | x : array_like
y : array_like
err_msg : string
verbose : bool
|
---|---|
Raises: | AssertionError :
|
See also
Examples
the first assert does not raise an exception
>>> np.testing.assert_array_equal([1.0,2.33333,np.nan],
[np.exp(0),2.33333, np.nan])
assert fails with numerical inprecision with floats
>>> np.testing.assert_array_equal([1.0,np.pi,np.nan],
[1, np.sqrt(np.pi)**2, np.nan])
...
<type 'exceptions.ValueError'>:
AssertionError:
Arrays are not equal
<BLANKLINE>
(mismatch 50.0%)
x: array([ 1. , 3.14159265, NaN])
y: array([ 1. , 3.14159265, NaN])
use assert_array_almost_equal for these cases instead
>>> np.testing.assert_array_almost_equal([1.0,np.pi,np.nan],
[1, np.sqrt(np.pi)**2, np.nan], decimal=15)