[SciPy-User] Reduction of spatial with small differences

federico vaggi vaggi.federico at gmail.com
Fri Jul 5 08:02:05 EDT 2013


The easiest way is probably to cluster your points, then pick the centroids
of the clusters as your new points.

http://docs.scipy.org/doc/scipy/reference/cluster.html has the functions
that you want.

Alternatively, if you want a more naive implementation:

You can do something like this:

from scipy.spatial.distance import pdist, squareform

X= [[1, 2, 2], [1, 3, 3], [1, 4, 4], [1, 4, 4], [1, 5, 5], [1, 6, 6], [1,
6.1, 6],
[1, 6.1, 6.1], [1, 6.2, 6.1]]

eps = 0.2

close_idx = squareform(pdist(X, 'euclidean'))pdist(X, 'euclidean')) < eps

(you don't have to work with the squareform, but it's much much easier).

and that gives you the indices of the pairs that are close enough to each
other.

However - this approach becomes very complicated if you have situations
where multiple clusters of points are close to each other.


Message: 1
> Date: Thu, 4 Jul 2013 08:50:15 +0100 (BST)
> From: Franz Engel <franz_lambert_engel at yahoo.de>
> Subject: [SciPy-User] Reduction of spatial with small differences
> To: "scipy-user at scipy.org" <scipy-user at scipy.org>
> Message-ID:
>         <1372924215.90932.YahooMailNeo at web172205.mail.ir2.yahoo.com>
> Content-Type: text/plain; charset="iso-8859-1"
>
> Hello,
>
> I have an numpy.array with 3D points. Some of the points are very close to
> each other. Now I want reduce points they have a distance smaller than x.
> For example
> rawArray
> [[1 2 2]
> ?[1 3 3]
> ?[1 4 4]
> ?[1 4 4]
> ?[1 5 5]
> ?[1 6 6]
> ?[1 6.1 6]
> ?[1 6.1 6.1]
> ?[1 6.2 6.1]]
>
> make reduction
> [[1 2 2]
> ?[1 3 3]
> ?[1 4 4]
> ?[1 5 5]
> ?[1 6.1 6.1]]
>
> Is there a common way to do that? Or is thera a good keyword what I can
> looking for?
>
> Regards,
> ? ? Franz
> -------------- next part --------------
> An HTML attachment was scrubbed...
> URL:
> http://mail.scipy.org/pipermail/scipy-user/attachments/20130704/722294a2/attachment-0001.html
>
> ------------------------------
>
> _______________________________________________
> SciPy-User mailing list
> SciPy-User at scipy.org
> http://mail.scipy.org/mailman/listinfo/scipy-user
>
>
> End of SciPy-User Digest, Vol 119, Issue 7
> ******************************************
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.scipy.org/pipermail/scipy-user/attachments/20130705/9f3316fc/attachment.html>


More information about the SciPy-User mailing list