[Numpy-discussion] np.choose() question

Andreas Hilboll lists@hilboll...
Tue Jun 8 11:24:51 CDT 2010


Hi there,

I have a problem, which I'm sure can somehow be solved using np.choose() 
- but I cannot figure out how :(

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.

A simple np.choose(idx,times) does not work (error "Need between 2 and 
(32) array objects (inclusive).").

Example:

idx = [[4,2],[3,1]]
times = [100,101,102,103,104]

 From these two I want to create an array

result = [[104,102],[103,101]]

How can this be done?

Thanks a lot for your insight!

Andreas



More information about the NumPy-Discussion mailing list