9951 explained code solutions for 126 technologies


python-numpyHow to check if arrays are equal


import numpy as np

a1 = np.array([[1, 2], [3, 4]])
a2 = np.array([[1, 2], [3, 4]])

is_equal = (a1==a2).all()ctrl + c
import numpy as np

load Numpy module for Python

np.array

declare Numpy array

a1

first sample array

a2

second sample array

is_equal

will contain True if a1 and a2 are equal

(a1==a2).all()

will return True if all elements of given arrays are equal