Re: [Numpy-discussion] Is there a way that indexing a matrix of data with a matrix of indices?
![](https://secure.gravatar.com/avatar/b450576bf795fc18adffd65a83fa0117.jpg?s=120&d=mm&r=g)
On Wed, 2017-11-29 at 12:00 -0500, numpy-discussion-request@python.org wrote:
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
![](https://secure.gravatar.com/avatar/45c62239fe401b600e94f7ec05e598a9.jpg?s=120&d=mm&r=g)
Thank you all, all of these methods work well :) ---- ZHUO QL (KDr2) http://kdr2.com On Thursday, November 30, 2017, 2:26:16 AM GMT+8, Eric Hermes <ehermes@chem.wisc.edu> wrote: On Wed, 2017-11-29 at 12:00 -0500, numpy-discussion-request@python.org wrote:
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
---- ZHUO QL (KDr2) http://kdr2.com
![](https://secure.gravatar.com/avatar/45c62239fe401b600e94f7ec05e598a9.jpg?s=120&d=mm&r=g)
Thank you all, all of these methods work well :) ---- ZHUO QL (KDr2) http://kdr2.com On Thursday, November 30, 2017, 2:26:16 AM GMT+8, Eric Hermes <ehermes@chem.wisc.edu> wrote: On Wed, 2017-11-29 at 12:00 -0500, numpy-discussion-request@python.org wrote:
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
---- ZHUO QL (KDr2) http://kdr2.com
participants (2)
-
Eric Hermes
-
ZHUO QL (KDr2)