8000 Wrong axis order when indexing by (int, slice, list) · Issue #6370 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

Wrong axis order when indexing by (int, slice, list) #6370

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

Closed
royf opened this issue Sep 26, 2015 · 1 comment
Closed

Wrong axis order when indexing by (int, slice, list) #6370

royf opened this issue Sep 26, 2015 · 1 comment

Comments

@royf
Copy link
royf commented Sep 26, 2015

Advanced indexing sometimes gives the result transposed w.r.t. the expected result.
This occurs when indexing by (int, slice, list), but not (int, slice, slice) or (slice, int, list).

Example:

>>> np.version.full_version
'1.9.3'
>>> a = np.arange(24).reshape((4, 3, 2))

Incorrect:

>>> a[1, :, [0, 1]].shape
(2, 3)

Correct:

>>> a[1, :, :].shape
(3, 2)
>>> a[:, 1, :].shape
(4, 2)
>>> a[:, 1, [0, 1]].shape
(4, 2)

The incorrect result is the transpose of the correct one:

>>> (a[1, :, [0, 1]] == a[1, :, :].T).all()
True
@jaimefrio
Copy link
Member

This is actually the documented behavior: the first and last index are considered to be fancy indices, and when more than one non-contiguous axis is fancy-indexed, the result of indexing those axes is grouped before any of the non-fancy indexed axes.

It's confusing, and there is an ongoing discussion to provide a more intuitive indexing, see #6075 and #6256, but it is not a bug, but a feature!

I'm going to close this, but feel free to continue the discussion if you need clarification.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants
0