Reputation: 2072
Suppose there is a matrix A
and a matrix B
. Is there a logical statement that can return only one value, either True
or False
based on whether all elements of A
are identical to all elements in B
?
For example A = array([[1, 0, 0],[0, 1, 0]])
and B = array([[1, 0, 0],[0, 1, 0]])
, A == B
returns True
and False
per element of every row and every column
Upvotes: 1
Views: 344
Reputation: 64338
Use np.array_equal
.
Also, you can apply .all()
to the equality-bool-array you got by comparing A==B
, like this:
(A==B).all()
The latter is slightly less efficient than the former (creates a temporary bool array), but just as common.
If comparing floats, where you typically want the value to be close but not necessarily identical, use np.allclose
.
Upvotes: 3