[SciPy-User] indexing question

Nick Choly ncholy@gmail....
Thu Jan 24 16:14:53 CST 2013

I'm fairly new to this, so apologies in advance.
Let's say I have a 3-d array A[i,j,k] of shape (Ni,Nj,Nk), and a list of
labels I[k], where I[k] belongs to 0...Ni-1.
I want to create a new, 2-d array B[j,k] = A[I[k], j, k].
I've found one solution to this, which is:
ind_i = np.tile(I, (1,Nj)).T
ind_j = np.tile(np.arange(Nj), (1,Nk))
ind_k = np.tile(np.arange(Nk), (1, Nj)).T
B = A[ind_i, ind_j, ind_k]

but something seems...not ideal about this.  Can someone tell me if there's
a simpler, better way?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/scipy-user/attachments/20130124/f508c5d2/attachment.html 

More information about the SciPy-User mailing list