KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
Is there an idiomatic way to compare two NumPy arrays that would treat NaNs as being equal to each other (but not equal to anything other than a NaN). For example, I want the following two arrays to compare equal: np.array([1.0, np.NAN, 2.0]) np.array([1.0, np.NAN, 2.0]) and the following two arrays to compare unequal: np.array([1.0, np.NAN, 2.0]) np.array([1.0, 0.0, 2.0]) I am looking for a method that would produce a scalar Boolean outcome. The following would do it: np.all((a == b) | (np.isnan(a) & np.isnan(b))) but it's clunky and creates all those intermediate arrays. Is there a way that's easier on the eye and makes better use of memory? P.S. If it helps, the arrays are known to have the same shape and dtype.
Tags (comma-separated)
Save Edits
Cancel