Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
204 views
in Technique[技术] by (71.8m points)

python - 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?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...