-
-
Notifications
You must be signed in to change notification settings - Fork 10.9k
Why does indexing an array after boolean comparison provide different results than doing a boolean comparison of an index? #10982
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Numpy has different promotion rules for scalars vs arrays, which I'd consider to be a bug (#10322) In this case, Your first example is computing |
@eric-wieser ah perfect. That's exactly what I was looking for. So in the first example numpy treats the values of the arr as np.float32 to match np.pi correct? |
You have that backwards. In the first example numpy throws away precision from np.pi first, casting it from float64 to float32 |
Oh right that's totally my bad. Guess i was reading too fast |
This question has been answered, and links to relevant bug reports are made, so closing the issue. Please reopen if you think it tracks something distinct not duplicated in another issue. |
So for context this question comes from this post on stackoverflow: https://stackoverflow.com/questions/50047174/array-comparison-not-matching-elementwise-comparison-in-numpy#50047327
Would someone be able to explain the difference in the way numpy approaches the problem? It looks like using np.float64 explicitly fixes the problem, but I'm curious to know if numpy does a different casting in the two indexing methods.
The text was updated successfully, but these errors were encountered: