On Tue, Aug 17, 2010 at 11:30 AM, Angus McMorland <[email protected]> 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 > [email protected] > http://mail.scipy.org/mailman/listinfo/numpy-discussion > _______________________________________________ NumPy-Discussion mailing list [email protected] http://mail.scipy.org/mailman/listinfo/numpy-discussion
