[Numpy-discussion] fancy indexing question
josef.pktd@gmai...
josef.pktd@gmai...
Tue Aug 17 11:18:28 CDT 2010
On Tue, Aug 17, 2010 at 11:30 AM, Angus McMorland <amcmorl@gmail.com> wrote:
> Hi all,
>
> I'm having a bit of a brain block about the following fancy indexing
> question, and am hoping someone can point me in the right direction. I
> have a 3-d array `a` that I want to reorder along its 0th dimension
> differently for each 1st dimension, with the indices given in a 2-d
> array `ord`. I can achieve this as follows
>
> a = np.random.randint(10, size=(4,3,2))
> ord = np.array([[3,2,1,0],[0,2,1,3],[3,0,2,1]]).T
> b = a[ord][:,np.eye(3, dtype=bool),:]
>
> but it seems like it should be possible to do this in one indexing
> step and avoid the intermediate and the eye call. Any suggestions
> gratefully received.
>>> a = np.random.randint(10, size=(4,3,2))
>>> ord = np.array([[3,2,1,0],[0,2,1,3],[3,0,2,1]]).T
>>> b = a[ord][:,np.eye(3, dtype=bool),:]
>>> (a[ord, np.arange(3), :] == b).all()
True
TDD without looking to closely what it is
Josef
>
> Thanks,
>
> Angus.
> --
> AJC McMorland
> Post-doctoral research fellow
> Neurobiology, University of Pittsburgh
> _______________________________________________
> NumPy-Discussion mailing list
> NumPy-Discussion@scipy.org
> http://mail.scipy.org/mailman/listinfo/numpy-discussion
>
More information about the NumPy-Discussion
mailing list