Sometimes, we want to compare two NumPy arrays for equality, element-wise with Python.
In this article, we’ll look at how to compare two NumPy arrays for equality, element-wise with Python.
How to compare two NumPy arrays for equality, element-wise with Python?
To compare two NumPy arrays for equality, element-wise with Python, we can use the ==
operator and the all
method.
For instance, we write
(A == B).all()
to compare NumPy arrays A
and B
with ==
for equality element-wise.
And then we call all
to return True
if all elements are equal in both arrays and False
otherwise.
Conclusion
To compare two NumPy arrays for equality, element-wise with Python, we can use the ==
operator and the all
method.