Python | numpy.assert_allclose () method

With the numpy.assert_allclose() method we can get assertion errors when two array objects are not equal up to the mark with numpy.assert_allclose () .

Syntax: numpy.assert_allclose (actual_array, desired_array)

Return : Return the Assertion error if two array objects are not equal.

Example # 1:
In this example, we see that with numpy.assert_allclose () we can get an assertion error if the two arrays are not equal.

# NumPy import

import numpy as np

 
# using the numpy.assert_allclose () method

gfg 1 = [ 1 , 2 , 3 ]

gfg2 = np.array (gfg1)

 

if np.testing.assert_allclose (gfg1, gfg2):

print ( "Matched" )

Output:

Matched

Example # 2:

# NumPy import

import numpy as np

  
# using the numpy.assert_allclose () method

gfg1 = [ 1 , 2 , 3 ]

gfg2 = np.array ([ 4 , 5 , 6 ])

 

print (np.testing.assert_allclose (gfg1, gfg2))

Output:

Mismatch: 100% 
Max absolute difference: 3
Max relative difference: 0.75
gfg1: array ([1, 2, 3])
gfg2: array ([4, 5, 6])