[SciPy-User] Reduction of spatial with small differences

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[SciPy-User] Reduction of spatial with small differences

flambert
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

_______________________________________________
SciPy-User mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/scipy-user
Reply | Threaded
Open this post in threaded view
|

Re: Reduction of spatial with small differences

Zachary Pincus-2
> 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.

You'll probably need to specify your problem a bit more clearly: what if you have an evenly-spaced array of points that are 0.9x distance apart? Should that be reduced to a single point?

Depending on how pathological your data are, this could basically be a clustering problem. If your data are guaranteed non-pathological (all points distantly spaced except small clusters spaced within x) then all you need to do is find those clusters, which you could do by calculating the full distance matrix (exact) or with a kd-tree (fast), both available in scipy.spatial.

Zach
_______________________________________________
SciPy-User mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/scipy-user
Reply | Threaded
Open this post in threaded view
|

Re: Reduction of spatial with small differences

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


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 <[hidden email]>
Subject: [SciPy-User] Reduction of spatial with small differences
To: "[hidden email]" <[hidden email]>
Message-ID:
        <[hidden email]>
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
[hidden email]
http://mail.scipy.org/mailman/listinfo/scipy-user


End of SciPy-User Digest, Vol 119, Issue 7
******************************************


_______________________________________________
SciPy-User mailing list
[hidden email]
http://mail.scipy.org/mailman/listinfo/scipy-user