[SciPy-user] remove duplicate points...
Pauli Virtanen
pav at iki.fi
Wed Apr 23 11:47:27 EDT 2008
Wed, 23 Apr 2008 11:09:07 -0400, Angus McMorland wrote:
[clip]
> On 23/04/2008, fred <fredmfp at gmail.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
[clip]
Something like this works, although it's probably not optimal:
import numpy as np
z = np.array([[1,2,3,4],
[4,5,1,3],
[1,2,5,3],
[4,5,1,3],
[7,7,4,1],
[4,5,1,3],
[4,5,1,3],
[6,4,5,5]])
# 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
else:
v |= w
unique_mask = np.hstack([True, v])
j_unique = j_sorted[unique_mask]
j_unique.sort()
# Done:
z_unique = z[j_unique]
print z_unique
More information about the SciPy-User
mailing list