[Numpy-discussion] Forcing new dimensions to appear at front in advanced indexing
diagonaldevice at gmail.com
Wed Jun 20 09:15:27 EDT 2018
> There is a way that will generally work using triple indexing:
> arr[..., None, None][orig_indx + (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?
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the NumPy-Discussion