-
-
Notifications
You must be signed in to change notification settings - Fork 12.2k
ENH: Allow for a flatiter index on a flatiter object #27342
Copy link
Copy link
Closed
Description
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 indexIt 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?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels