8000 numpy.index_exp isn't quite consistent with direct indexing in backward compatibility case · Issue #9797 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

numpy.index_exp isn't quite consistent with direct indexing in backward compatibility case #9797

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

Open
FrozenBob opened this issue Sep 30, 2017 · 1 comment

Comments

@FrozenBob
Copy link

The numpy.s_/numpy.index_exp docs claim the following:

For any index combination, including slicing and axis insertion, a[indices] is the same as a[np.index_exp[indices]] for any array a.

However, this appears to only be completely accurate for numpy.s_, due to the weird backward compatibility logic where certain non-tuple sequences are converted to tuples. For example,

In [7]: a = np.zeros([4, 4])

In [8]: indices = [[0, 1], [2, 3]]

In [9]: a[indices].shape
Out[9]: (2,)

In [10]: a[np.s_[indices]].shape
Out[10]: (2,)

In [11]: a[np.index_exp[indices]].shape
Out[11]: (2, 2, 4)

numpy.index_exp's tuple creation doesn't reflect the backward compatibility handling. Either the docs or the behavior should be adjusted to match the other.

@eric-wieser
Copy link
Member
eric-wieser commented Sep 30, 2017

There's a PR to deprecate the weird backwards compatibility at #9686.

What's actually true is that:

  • a[np.index_exp[x, y, z]] is the same as a[x, y, z]
  • a[np.index_exp[x]] is the same as a[(x,)]
  • a[(x,)] is usually the same as a[x], unless the latter invokes the compatibility behaviour

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

No branches or pull requests

2 participants
0