[Numpy-discussion] Forcing new dimensions to appear at front in advanced indexing (original) (raw)
Michael Lamparski diagonaldevice at gmail.com
Wed Jun 20 09:15:27 EDT 2018
- Previous message (by thread): [Numpy-discussion] Forcing new dimensions to appear at front in advanced indexing
- Next message (by thread): [Numpy-discussion] Forcing new dimensions to appear at front in advanced indexing
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
There is a way that will generally work using triple indexing:
arr[..., None, None][origindx + (slice(None), np.array(0))][..., 0]
Impressive! (note: I fixed the * typo in the quote)
The first and last indexing operation is just a view creation, so it is basically a no-op. Now doing this gives me the shiver, but it will work always. If you want to have a no-copy behaviour in case your original index is ont an advanced indexing operation, you should replace the np.array(0) with just 0.
I agree about the shivers, but any workaround is good to have nonetheless.
If the index is not an advanced indexing operation, does it not suffice to simply apply the index tuple as-is?
Michael -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/numpy-discussion/attachments/20180620/42f1e1a4/attachment.html>
- Previous message (by thread): [Numpy-discussion] Forcing new dimensions to appear at front in advanced indexing
- Next message (by thread): [Numpy-discussion] Forcing new dimensions to appear at front in advanced indexing
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]