Re: [Numpy-discussion] np.choose() question

2010-06-08 Thread Andreas
Hi, actually, I meant to reply to Mark's mail, as I used his solution ;) Thanks! On 06/08/2010 09:21 PM, Gökhan Sever wrote: > If we were at so or ask.scipy I would vote for Mark's solution :) > > Usually in cases like yours, I tend to use the shortest version of the > solutions. > > On Tue, J

Re: [Numpy-discussion] np.choose() question

2010-06-08 Thread Gökhan Sever
On Tue, Jun 8, 2010 at 2:32 PM, Hans Meine wrote: > > > 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[

Re: [Numpy-discussion] np.choose() question

2010-06-08 Thread Hans Meine
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 ha

Re: [Numpy-discussion] np.choose() question

2010-06-08 Thread Gökhan Sever
If we were at so or ask.scipy I would vote for Mark's solution :) Usually in cases like yours, I tend to use the shortest version of the solutions. On Tue, Jun 8, 2010 at 2:08 PM, Andreas Hilboll wrote: > Hi, > > > newtimes = [times[idx[x][y]] for x in range(2) for y in range(2)] > > np.array(n

Re: [Numpy-discussion] np.choose() question

2010-06-08 Thread Andreas Hilboll
Hi, > newtimes = [times[idx[x][y]] for x in range(2) for y in range(2)] > np.array(newtimes).reshape(2,2) > array([[104, 102], >[103, 101]]) Great, thanks a lot! Cheers, Andreas. ___ NumPy-Discussion mailing list NumPy-Discussion@scipy.or

Re: [Numpy-discussion] np.choose() question

2010-06-08 Thread Mark Miller
Not pretty, but it works: >>> idx array([[4, 2], [3, 1]]) >>> times array([100, 101, 102, 103, 104]) >>> numpy.reshape(times[idx.flatten()],idx.shape) array([[104, 102], [103, 101]]) >>> On Tue, Jun 8, 2010 at 10:09 AM, Gökhan Sever wrote: > > > On Tue, Jun 8, 2010 at 1

Re: [Numpy-discussion] np.choose() question

2010-06-08 Thread Gökhan Sever
On Tue, Jun 8, 2010 at 11:24 AM, Andreas Hilboll 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 h

[Numpy-discussion] np.choose() question

2010-06-08 Thread Andreas Hilboll
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,). Ou