Are two arrays element-wise equal?
EasyNumPy Programs · 8 of 100
Write a NumPy program to test whether two arrays are element-wise equal.
Input[3, 8, 5], [3, 8, 5]
Output[ True True True] True
Approach
== compares element by element; np.array_equal gives one answer.
Solution
Python
import numpy as npa, b = np.array([3, 8, 5]), np.array([3, 8, 5])print(a == b, np.array_equal(a, b))
Output
[ True True True] True
Learn the concept
New to this topic? Read the lesson, then come back.
More numpy programs
← All 100 NumPy Programs