Mohit Lamba
Mohit Lamba

Reputation: 1383

is_equal operator in NumPy

I have two NumPy ndarrays a and b. I want to check if they are equal as if a=b.copy(). However, if I use the == operator it returns an element-wise list of True or False. I want a binary answer, i.e. if all the elements are equal in terms of value, type, etc then a single True should be returned else False. Is there an operator in NumPy to achieve this?

Upvotes: 0

Views: 440

Answers (1)

Ehsan
Ehsan

Reputation: 12407

You are looking for this:

np.array_equal(a,b)

or alternatively:

(a==b).all()

Also, depending on your application and array dtype, I would suggest checking np.allclose and np.array_equiv too.

Upvotes: 1

Related Questions