On Thursday, November 30, 2017, 2:26:16 AM GMT+8, Eric Hermes <ehermes@chem.wisc.edu> wrote:
wrote:
> Date: Wed, 29 Nov 2017 14:56:28 +0000 (UTC)
> Subject: [Numpy-discussion] Is there a way that indexing a matrix of
> data with a matrix of indices?
> Content-Type: text/plain; charset="utf-8"
>
> Hi, all
> suppose:
> - D, is the data matrix, its shape is? M x N- I, is the indices
> matrix, its shape is M x K,? K<=N
> Is there a efficient way to get a Matrix R with the same shape of I
> so that R[x,y] = D[x, I[x,y]] ?
> A nested for-loop or list-comprehension is too slow for me.??
> Thanks.
I don't know if this will be substantially faster, but you can try the
following:
I += np.array(range(M))[:, np.newaxis] * N
R = D.ravel()[I.ravel()].reshape((M, K))
Eric
> ----
> -------------- next part --------------
> An HTML attachment was scrubbed...
> discussion/attachments/20171129/baeaddc0/attachment-0001.html>
_______________________________________________
NumPy-Discussion mailing list