Indexing and lookup issues
Hi everyone I suspect this is easy but I'm stuck say I have a 1D array: t = [10,11,12] and a 2D array: id = [[0,1,0] [0,2,0] [2,0,2]] In could in IDL do y = t[id] which would produce: y = [[10,11,10] [10,12,10] [12,10,12]] i.e. use the indexes in id on the lookup array t. Is there an easy way to do this in numpy? Cheers Ross -- Ross Williamson University of Chicago Department of Astronomy & Astrophysics 773-834-9785 (office) 312-504-3051 (Cell)
On 22 September 2010 16:38, Ross Williamson <rosswilliamson.spt@gmail.com> wrote:
Hi everyone
I suspect this is easy but I'm stuck
say I have a 1D array:
t = [10,11,12]
and a 2D array:
id = [[0,1,0] [0,2,0] [2,0,2]]
In could in IDL do y = t[id] which would produce:
y = [[10,11,10] [10,12,10] [12,10,12]]
i.e. use the indexes in id on the lookup array t.
Is there an easy way to do this in numpy?
In [1]: t = np.array([10,11,12]) In [2]: id = np.array([[0,1,0], [0,2,0], [2,0,2]]) In [3]: t[id] Out[3]: array([[10, 11, 10], [10, 12, 10], [12, 10, 12]]) Anne
Thank you Anne I was doing something totally stupid at my end. Ross On Wed, Sep 22, 2010 at 3:42 PM, Anne Archibald <aarchiba@physics.mcgill.ca> wrote:
On 22 September 2010 16:38, Ross Williamson <rosswilliamson.spt@gmail.com> wrote:
Hi everyone
I suspect this is easy but I'm stuck
say I have a 1D array:
t = [10,11,12]
and a 2D array:
id = [[0,1,0] [0,2,0] [2,0,2]]
In could in IDL do y = t[id] which would produce:
y = [[10,11,10] [10,12,10] [12,10,12]]
i.e. use the indexes in id on the lookup array t.
Is there an easy way to do this in numpy?
In [1]: t = np.array([10,11,12])
In [2]: id = np.array([[0,1,0], [0,2,0], [2,0,2]])
In [3]: t[id] Out[3]: array([[10, 11, 10], [10, 12, 10], [12, 10, 12]])
Anne _______________________________________________ NumPy-Discussion mailing list NumPy-Discussion@scipy.org http://mail.scipy.org/mailman/listinfo/numpy-discussion
-- Ross Williamson University of Chicago Department of Astronomy & Astrophysics 773-834-9785 (office) 312-504-3051 (Cell)
participants (2)
-
Anne Archibald -
Ross Williamson