Skip to content

ENH: Allow for a flatiter index on a flatiter object #27342

@lysnikolaou

Description

@lysnikolaou

Proposed new feature or change:

Currently, indexing a flatiter with an array object and vice-versa is permitted.

In [1]: a = np.arange(9).reshape((3, 3))

In [2]: a
Out[2]:
array([[0, 1, 2],
       [3, 4, 5],
       [6, 7, 8]])

In [3]: b = np.array([0, 4, 5, 7])

In [4]: b
Out[4]: array([0, 4, 5, 7])

In [5]: a.flat[b]
Out[5]: array([0, 4, 5, 7])

In [6]: a = np.arange(9)

In [7]: a
Out[7]: array([0, 1, 2, 3, 4, 5, 6, 7, 8])

In [8]: a[b.flat]
Out[8]: array([0, 4, 5, 7])

However, indexing a flatiter with a flatiter results in an exception:

In [9]: a.flat[b.flat]
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
Cell In[9], line 1
----> 1 a.flat[b.flat]

IndexError: unsupported iterator index

It would be relatively straightforward to allow flatiter objects to be index by other flatiter objects as well, and it seems that there's no downsides to this. Thoughts?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions