-
-
Notifications
You must be signed in to change notification settings - Fork 12.2k
DOC: Confusing advanced indexing when mixing tuple, integer, and range #30022
Copy link
Copy link
Open
Labels
Description
Issue with current documentation:
When addressing a 3+ dim array with a tuple in its 3rd or later dims, the returned shape depends on the order of previous ranges/integers:
>>> k = np.ones((4,5,6),)
>>> k[:,0,(1,2)].shape
(4, 2) #expected
>>> k[0,:,(1,2)].shape
(2, 5) #unexpected! actually transpose of right answer
>>> k[0,:,:][:,(1,2)].shape
(5, 2) #workaround
>>> k[:1,:,(1,2)].shape
(1, 5, 2) #workaround
This might be an actual bug. It seems the actually unexpected case should be canonically correct: zero getting broadcast to (0,0). The documentation is unclear as to how this situation should behave, the example in that case uses unclear variable names:
result[i_1, ..., i_M] == x[ind_1[i_1, ..., i_M], ind_2[i_1, ..., i_M],
..., ind_N[i_1, ..., i_M]]
from here:
https://numpy.org/doc/stable/user/basics.indexing.html#integer-array-indexing
Idea or request for content:
The priority between ranges and tuples seems to be undefined and I don't know what it should be. If the described behavior is expected, the documentation should describe behavior when mixing with ranges better.
Reactions are currently unavailable