[Numpy-discussion] Efficient removal of duplicates

Hanno Klemm klemm@phys.ethz...
Tue Dec 16 03:09:33 CST 2008


Thanks Daran,

that works like a charm!

Hanno

On Tue, Dec 16, 2008, Daran Rife <drife@ucar.edu> 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 for i, x in enumerate(l) if not i or x != l[i-1]] # <----
> a_unique = np.asarray(unique)
> 
> 
> Daran
> 
> --
> 
> On Dec 15, 2008, at 5:24 PM, 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.asarray(unique)
>>
>> Performance of this approach should be highly scalable.
>>
>> Daran
>>
>> --
>>
>>
>> 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 I can think of involves loops.
>>
>> Thanks and regards,
>> Hanno
> 
> _______________________________________________
> Numpy-discussion mailing list
> Numpy-discussion@scipy.org
> http://projects.scipy.org/mailman/listinfo/numpy-discussion
> 

-- 
Hanno Klemm
klemm@phys.ethz.ch




More information about the Numpy-discussion mailing list