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
Indexing behavior with ellipses is non-intuitive. #16956
Comments
This looks like a particularly nasty corner case - I guess we consider the |
We ran into this issue when trying to replicate numpy indexing. I think this is a weird interaction between two rules:
This special case is triggered because a 0-d tuple (when ... is used with all indices present) is still considered a basic index block, when it should really be invisible. |
I agree that this is all confusing, and I would not even have been certain without checking what happens here. But, it does seem like the correct choice to me. Why should it be truly "invisible"? In the end, this is simply confusing, and we would have to pick up |
I'm with @seberg's argument that the current behavior is the best generalization. We could certainly make sure the docs are clearer though. |
I didn't know about that proposal, thanks for the reference @seberg! Let me rephrase just to make sure I understand your argument. Say we label advanced indices
These rules are consistent once you know what class (A or B) My intuition that 0-d blocks should be no-op was driven by how tuples behave, where for any i: int
M: Tuple[int, ...]
N = ()
assert M[:i] + N + M[i:] == M This conflicts with the During development we would switch how we did the indexing and would insert Thanks for taking a look! I can submit a doc PR if you'd like. |
@antonl a doc PR is always welcome, there are many improvements possible here. |
Closing, docs can probably be improved, but they always can and there is nothing concrete here (beyond implementing NEP 21 one day). |
Array indexing with ellipses can be extremely counter-intuitive. For instance, in the following example the introduction of a redundant ellipses alters the shape of the output:
I don't think this is desired behavior, but it does seem to stem directly from design decisions with regards to how complex indexing is handled.
Numpy/Python version information:
1.17.3 3.7.5 (default, Oct 25 2019, 10:52:18)
[Clang 4.0.1 (tags/RELEASE_401/final)]
The text was updated successfully, but these errors were encountered: