Re: [Numpy-discussion] Quick array value assignment based on common values

2010-08-04 Thread PHobson
utions you've outlined. Thanks again! -paul From: numpy-discussion-boun...@scipy.org [mailto:numpy-discussion-boun...@scipy.org] On Behalf Of John Salvatier Sent: Wednesday, August 04, 2010 6:23 PM To: Discussion of Numerical Python Subject: Re: [Numpy-discussion] Quick array value assignme

Re: [Numpy-discussion] Quick array value assignment based on common values

2010-08-04 Thread John Salvatier
Perhaps try the following: 1) sort x by x[:,0] 2) sort y by y[:,0] 3) loop through both at the same time building an array of indexes A that tells you the index of y[i,0] in x or just building a new array z with the value if you don't need them in order 4) if you do need them in order, unsort A by

Re: [Numpy-discussion] Quick array value assignment based on common values

2010-08-04 Thread John Salvatier
How exactly are you looping? That sounds absurdly slow. What you need is a fast dictionary. On Wed, Aug 4, 2010 at 6:00 PM, Gökhan Sever wrote: > > > On Wed, Aug 4, 2010 at 6:59 PM, wrote: > >> Hey folks, >> >> I've one array, x, that you could define as follows: >> [[1, 2.25], >> [2, 2.50],

Re: [Numpy-discussion] Quick array value assignment based on common values

2010-08-04 Thread Gökhan Sever
On Wed, Aug 4, 2010 at 8:00 PM, Gökhan Sever wrote: > > > On Wed, Aug 4, 2010 at 6:59 PM, wrote: > >> Hey folks, >> >> I've one array, x, that you could define as follows: >> [[1, 2.25], >> [2, 2.50], >> [3, 2.25], >> [4, 0.00], >> [8, 0.00], >> [9, 2.75]] >> >> Then my second array, y, is:

Re: [Numpy-discussion] Quick array value assignment based on common values

2010-08-04 Thread Gökhan Sever
On Wed, Aug 4, 2010 at 6:59 PM, wrote: > Hey folks, > > I've one array, x, that you could define as follows: > [[1, 2.25], > [2, 2.50], > [3, 2.25], > [4, 0.00], > [8, 0.00], > [9, 2.75]] > > Then my second array, y, is: > [[1, 0.00], > [2, 0.00], > [3, 0.00], > [4, 0.00], > [5, 0.00], >

Re: [Numpy-discussion] Quick array value assignment based on common values

2010-08-04 Thread PHobson
ere. -paul From: numpy-discussion-boun...@scipy.org [mailto:numpy-discussion-boun...@scipy.org] On Behalf Of John Salvatier Sent: Wednesday, August 04, 2010 5:34 PM To: Discussion of Numerical Python Subject: Re: [Numpy-discussion] Quick array value assignment based on common values Are they num

Re: [Numpy-discussion] Quick array value assignment based on common values

2010-08-04 Thread Sturla Molden
> Is there a concise, Numpythonic way to copy the values of x[:,1] over to > y[:,1] where x[:,0] = y[:,0]? Resulting in, z: First use mask = (x[:,0] == y[:,0]) # integers or mask = np.abs(x[:,0] - y[:,0]) < eps # floats and then y[mask,1] = x[mask,1] Sturla __

Re: [Numpy-discussion] Quick array value assignment based on common values

2010-08-04 Thread John Salvatier
Are they numbered like that? If so you can index into the first array by the second one. x[y[:,0], 1] if you can't get them into an indexable format, I think it's going to be slow no matter how you do it. On Wed, Aug 4, 2010 at 4:59 PM, wrote: > Hey folks, > > I've one array, x, that you could d

[Numpy-discussion] Quick array value assignment based on common values

2010-08-04 Thread PHobson
Hey folks, I've one array, x, that you could define as follows: [[1, 2.25], [2, 2.50], [3, 2.25], [4, 0.00], [8, 0.00], [9, 2.75]] Then my second array, y, is: [[1, 0.00], [2, 0.00], [3, 0.00], [4, 0.00], [5, 0.00], [6, 0.00], [7, 0.00], [8, 0.00], [9, 0.00], [10,0.00]] Is there a