[Numpy-discussion] fancy indexing question

Angus McMorland amcmorl@gmail....
Tue Aug 17 10:30:42 CDT 2010


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.

Thanks,

Angus.
-- 
AJC McMorland
Post-doctoral research fellow
Neurobiology, University of Pittsburgh


More information about the NumPy-Discussion mailing list