Wednesday, July 3, 2024
HomeLanguagesPythonPython | Numpy np.assert_equal() method

Python | Numpy np.assert_equal() method

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

Calisto Chipfumbu
Calisto Chipfumbuhttp://cchipfumbu@gmail.com
I have 5 years' worth of experience in the IT industry, primarily focused on Linux and Database administration. In those years, apart from learning significant technical knowledge, I also became comfortable working in a professional team and adapting to my environment, as I switched through 3 roles in that time.
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments