[SciPy-user] remove duplicate points...

Angus McMorland amcmorl@gmail....
Wed Apr 23 10:09:07 CDT 2008

Hi Fred et al,

On 23/04/2008, fred <fredmfp@gmail.com> wrote:
> Hi,
>  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). I
doubt this is very efficient, but usually when I post these sorts of
answers it stimulates the gurus to post better solutions, which is
always good.

import numpy as np

def remove_dups(ptsar, atol=1e-8):
    '''removes duplicate entries from pts array'''
    prods = ptsar.prod(axis=1)
    sorted = ptsar[prods.argsort()]
    prodsorted = prods[prods.argsort()]
    diffs = np.greater(np.absolute(np.diff(prodsorted)), atol)
    diffs = np.hstack(((True,), diffs))
    return sorted[diffs]

I hope that helps,

AJC McMorland, PhD candidate
Physiology, University of Auckland

(Nearly) post-doctoral research fellow
Neurobiology, University of Pittsburgh

More information about the SciPy-user mailing list