Skip to content

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

Open
@FrozenBob

Description

@FrozenBob

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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions