[Numpy-discussion] np.choose() question
Tue Jun 8 12:09:26 CDT 2010
On Tue, Jun 8, 2010 at 11:24 AM, Andreas Hilboll <email@example.com> wrote:
> 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
> A simple np.choose(idx,times) does not work (error "Need between 2 and
> (32) array objects (inclusive).").
> 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!
> NumPy-Discussion mailing list
Here is a non numpy.choose solution:
newtimes = [times[idx[x][y]] for x in range(2) for y in range(2)]
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the NumPy-Discussion