Open In App

Python | Numpy np.assert_equal() method

Improve
Improve
Like Article
Like
Save
Share
Report

With the help of np.assert_equal() method, we can get the assertion error when two objects are not equal by using np.assert_equal() method.

Syntax : np.assert_equal(actual, desired)
Return : Return assertion error if two object are unequal.

Example #1 :
In this example we can see that by using np.assert_equal() method, we are able to get the assertion error when two objects are not equal by using this method.




# import numpy and assert_equal
import numpy as np
import numpy.testing as npt
  
# using np.assert_equal() method
gfg = npt.assert_equal([1, 2], [1, 2])
  
print(gfg)


Output :

None

Example #2 :




# import numpy and assert_equal
import numpy as np
import numpy.testing as npt
  
# using np.assert_equal() method
gfg = npt.assert_equal([1, 2], [5, 2])
  
print(gfg)


Output :

AssertionError:
Items are not equal:
item=0

ACTUAL: 1
DESIRED: 5


Last Updated : 23 Jan, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads