Hi!

Am 08.06.2010 um 18:24 schrieb Andreas Hilboll:
> I have an array idx, which holds int values and has a 2d shape. All 
> values inside idx are 0 <= idx < n. And I have a second array times, 
> which is 1d, with times.shape = (n,).
> 
> Out of these two arrays I now want to create a 2d array having the same 
> shape as idx, and holding the values contained in times, as indexed by
> idx.

Funny, that's exactly what I wanted to do (idx being a label/region image here),
and what I tried today.

You will be happy to hear that the even simpler solution is to just use
fancy indexing (the name is justified here):

  times[idx]

will do the trick, too - no nead to flatten & reshape at all! :-)
(Given that both are ndarrays of course.)

HTH,
  Hans
_______________________________________________
NumPy-Discussion mailing list
NumPy-Discussion@scipy.org
http://mail.scipy.org/mailman/listinfo/numpy-discussion

Reply via email to