w3resource

NumPy Logic functions: array_equal() function

numpy.array_equal() function

The array_equal() function is True if two arrays have the same shape and elements, False otherwise.

Syntax:

numpy.array_equal(a1, a2)

Version: 1.15.0

Parameter:

Name Description Required /
Optional
a1, a2 Input arrays.
array_like
Required

Returns:
b : bool - Returns True if the arrays are equal.

NumPy.array_equal() method Example-1:

>>> import numpy as np
>>> np.array_equal([1, 3], [1, 3])

Output:

True

NumPy.array_equal() method Example-2:

>>> import numpy as np
>>> np.array_equal(np.array([2, 4]), np.array([2, 4]))

Output:

True

NumPy.array_equal() method Example-3:

>>> import numpy as np
>>> np.array_equal([2, 4], [2, 4, 6])

Output:

False

NumPy.array_equal() method Example-4:

>>> import numpy as np
>>> np.array_equal([1, 3], [2, 5])

Output:

False

Python - NumPy Code Editor:

Previous: isclose() function
Next: array_equiv() function



Follow us on Facebook and Twitter for latest update.