[SciPy-user] remove duplicate points...
Wed Apr 23 10:47:27 CDT 2008
Wed, 23 Apr 2008 11:09:07 -0400, Angus McMorland wrote:
> On 23/04/2008, fred <email@example.com> wrote:
> > I have array of 3D points:
> > [x0, y0, z0, v0]
> > [x1, y1, z1, v1]
> > ...
> > [xn, yn, zn, vn]
> > This array have duplicate elements (points), by construction.
> > How could I remove these duplicate elements ?
> I had to do this prior to Delaunay triangulation at one point, and wrote
Something like this works, although it's probably not optimal:
import numpy as np
z = np.array([[1,2,3,4],
# Find the indices of the unique entries
j_sorted = np.lexsort(z.T)
v = None
for q in z.T:
q = q[j_sorted]
w = (q[1:] != q[:-1])
if v is None:
v = w
v |= w
unique_mask = np.hstack([True, v])
j_unique = j_sorted[unique_mask]
z_unique = z[j_unique]
More information about the SciPy-user