[Numpy-discussion] np.choose() question

Hans Meine meine@informatik.uni-hamburg...
Tue Jun 8 14:32:28 CDT 2010


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):


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


More information about the NumPy-Discussion mailing list