[SciPy-user] remove duplicate points...

Stéfan van der Walt stefan@sun.ac...
Wed Apr 23 10:32:51 CDT 2008


2008/4/23 Angus McMorland <amcmorl@gmail.com>:
>  >  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 a quick routine to remove the duplicates, which works on the
>  assumption that unique pts will have a unique product (x * y * z).

That doesn't sound like a valid assumption?

Something like this should work, although it will shuffle the data:

import numpy as np

x = np.array([[1,2,3],[4,5,6],[1,3,4],[1,2,3],[4,5,6],[7,8,9],[1,2,3],[5,6,7],[1,3,4]])

N = len(x)
for i in xrange(N):
    if i < len(x):
        x = np.vstack((x[i],
		       x[~np.all(x[i] == x,axis=1)]))
    else:
	break

print x

Regards
Stéfan


More information about the SciPy-user mailing list