element-wise lookup on one ndarray to another ndarray of different shapes

Posted by fahhean on Stack Overflow See other posts from Stack Overflow or by fahhean
Published on 2010-06-02T09:38:42Z Indexed on 2010/06/02 9:44 UTC
Read the original article Hit count: 152

Filed under:
|

Hi,

I am new to numpy. Am wonder is there a way to do lookup of two ndarray of different shapes? for example, i have 2 ndarrays as below:

X = array([[0, 3, 6],
       [3, 3, 3],
       [6, 0, 3]])

Y = array([[0, 100],
       [3, 500],
       [6, 800]])

and would like to lookup each element of X in Y, then be able to return the second column of Y:

Z = array([[100, 500, 800],
       [500, 500, 500],
       [800, 100, 500]]) 

thanks, fahhean

© Stack Overflow or respective owner

Related posts about python

Related posts about numpy