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
Broadcasting errors with multi-dimensional boolean masks #13255
Comments
With boolean arrays, the code assumes you are trying to index either a single dimension or all elements at the same time - with the choice somewhat unfortunately guessed in a way that allows a single Part of the problem is that tuples and lists are treated as equivalent, something we're trying to move away from. Eventually, you'd handle the boolean array index by ensuring the mask was a double list. For now, though, I fear the only solution is to do cc @eric-wieser, who has been working to deprecate the "treat tuple as list" for indexing operations. p.s. Most annoying I find this difference:
|
Yes, |
I think Maybe that will be picked up some time. The NEP also says that at least for the current indexing multiple boolean indices should just be deprecated (I think whether to allow this specific use case may still have been contested – it is consistent, but may not have much use case and be pretty confusing in any case). |
Attempting to index a 2D array of shape [N, M] with two 1D boolean masks, shapes N and M, certain combinations of True and False lead to a broadcasting error (particularly when one is all false). I'm not sure if this behaviour is expected but it seems highly surprising and undesirable.
In the example below,
x[[False, True, True], [True, True, True]]
errors, whilex[[False, True, True], True]
andx[[False, True, True]]
have the expected behavior.Reproducing code example:
Error message:
Numpy/Python version information:
The text was updated successfully, but these errors were encountered: