[Numpy-discussion] Efficient removal of duplicates: Numpy discussion board

2009-03-29 Thread Daran L. Rife
ed return > the indices of the duplicate (or alternatively unique) values in a. > > > Here is the piece of code that you suggested at the time (Re: > [Numpy-discussion] Efficient removal of duplicates, posted on Tue, 16 Dec 2008 01:10:00 -0800) > > > -

Re: [Numpy-discussion] Efficient removal of duplicates

2008-12-16 Thread Sturla Molden
There was an discussion about this on the c.l.p a while ago. Using a sort will scale like O(n log n) or worse, whereas using a set (hash table) will scale like amortized O(n). How to use a Python set to get a unique collection of objects I'll leave to your imagination. Sturla Molden > On Mon, De

Re: [Numpy-discussion] Efficient removal of duplicates

2008-12-16 Thread Hanno Klemm
Thanks Daran, that works like a charm! Hanno On Tue, Dec 16, 2008, Daran Rife said: > Whoops! A hasty cut-and-paste from my IDLE session. > This should read: > > import numpy as np > > a = [(x0,y0), (x1,y1), ...] # A numpy array, but could be a list > l = a.tolist() > l.sort() > unique = [x

Re: [Numpy-discussion] Efficient removal of duplicates

2008-12-15 Thread Robert Kern
On Mon, Dec 15, 2008 at 18:24, Daran Rife wrote: > How about a solution inspired by recipe 18.1 in the Python Cookbook, > 2nd Ed: > > import numpy as np > > a = [(x0,y0), (x1,y1), ...] > l = a.tolist() > l.sort() > unique = [x for i, x in enumerate(l) if not i or x != b[l-1]] > a_unique = np.asarr

Re: [Numpy-discussion] Efficient removal of duplicates

2008-12-15 Thread Daran Rife
Whoops! A hasty cut-and-paste from my IDLE session. This should read: import numpy as np a = [(x0,y0), (x1,y1), ...] # A numpy array, but could be a list l = a.tolist() l.sort() unique = [x for i, x in enumerate(l) if not i or x != l[i-1]] # < a_unique = np.asarray(unique) Daran -- On Dec

Re: [Numpy-discussion] Efficient removal of duplicates

2008-12-15 Thread Daran Rife
How about a solution inspired by recipe 18.1 in the Python Cookbook, 2nd Ed: import numpy as np a = [(x0,y0), (x1,y1), ...] l = a.tolist() l.sort() unique = [x for i, x in enumerate(l) if not i or x != b[l-1]] a_unique = np.asarray(unique) Performance of this approach should be highly scalable.

Re: [Numpy-discussion] Efficient removal of duplicates

2008-12-15 Thread Robert Kern
On Mon, Dec 15, 2008 at 10:27, Hanno Klemm wrote: > > Hi, > > I the following problem: I have a relatively long array of points > [(x0,y0), (x1,y1), ...]. Apparently, I have some duplicate entries, which > prevents the Delaunay triangulation algorithm from completing its task. > > Question, is the

Re: [Numpy-discussion] Efficient removal of duplicates

2008-12-15 Thread Andrew Straw
Hanno Klemm wrote: > Hi, > > I the following problem: I have a relatively long array of points > [(x0,y0), (x1,y1), ...]. Apparently, I have some duplicate entries, which > prevents the Delaunay triangulation algorithm from completing its task. > > Question, is there an efficent way, of getting r

Re: [Numpy-discussion] Efficient removal of duplicates

2008-12-15 Thread Alan G Isaac
Hanno Klemm wrote: > I the following problem: I have a relatively long array of points > [(x0,y0), (x1,y1), ...]. Apparently, I have some duplicate entries, which > prevents the Delaunay triangulation algorithm from completing its task. > > Question, is there an efficent way, of getting rid of the

[Numpy-discussion] Efficient removal of duplicates

2008-12-15 Thread Hanno Klemm
Hi, I the following problem: I have a relatively long array of points [(x0,y0), (x1,y1), ...]. Apparently, I have some duplicate entries, which prevents the Delaunay triangulation algorithm from completing its task. Question, is there an efficent way, of getting rid of the duplicate entries? All