Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #98024
| From | Tom P <werotizy@freent.dd> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: Nearest neighbours of points |
| Date | 2015-10-31 22:28 +0100 |
| Message-ID | <d9kq38Ft8k9U1@mid.individual.net> (permalink) |
| References | <81947104-f6dd-48b3-ba7b-f03b0c5b6f39@googlegroups.com> |
On 10/24/2015 10:05 PM, Poul Riis wrote:
> I have N points in 3D, organized in a list. I want to to point out the numbers of the two that have the smallest distance.
> With scipy.spatial.distance.pdist I can make a list of all the distances, and I can point out the number of the minimum value of that list (see simple example below - the line with pts.append... should be indented three times). But I guess there is a standard (numpy?) routine which points out the numbers of the corresponding two points but I cannot find it. Can someone help?
>
> Poul Riis
>
>
>
>
> import numpy as np
> import scipy
> from scipy.spatial.distance import pdist
>
>
> pts=[]
> for i in range(-1,2):
> for j in range(-1,2):
> for k in range(-1,2): pts.append((i+np.random.random()/10,j+np.random.random()/10,k+np.random.random()/10))
> for i in range(0,len(pts)):
> print(pts[i])
> distances=scipy.spatial.distance.pdist(pts)
> n=np.argmin(distances)
> for i in range(0,len(distances)):
> print(i,distances[i])
> print('The minimum distance is: ',min(distances),' which has number ',n)
>
I won't claim to have the definitive answer but - is this a clustering
problem? Did you look at any machine learning packages?
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Nearest neighbours of points Poul Riis <priisdk@gmail.com> - 2015-10-24 13:05 -0700
Re: Nearest neighbours of points Christian Gollwitzer <auriocus@gmx.de> - 2015-10-24 22:45 +0200
Re: Nearest neighbours of points Poul Riis <priisdk@gmail.com> - 2015-10-24 15:44 -0700
Re: Nearest neighbours of points Christian Gollwitzer <auriocus@gmx.de> - 2015-10-25 09:55 +0100
Re: Nearest neighbours of points Poul Riis <priisdk@gmail.com> - 2015-10-25 05:00 -0700
Re: Nearest neighbours of points Peter Pearson <pkpearson@nowhere.invalid> - 2015-10-25 17:01 +0000
Re: Nearest neighbours of points Bartc <bc@freeuk.com> - 2015-10-25 12:36 +0000
Re: Nearest neighbours of points Fabien <fabien.maussion@gmail.com> - 2015-10-26 03:25 +0100
Re: Nearest neighbours of points Tom P <werotizy@freent.dd> - 2015-10-31 22:28 +0100
Re: Nearest neighbours of points Terry Reedy <tjreedy@udel.edu> - 2015-10-31 23:00 -0400
csiph-web