Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #97937
| From | Christian Gollwitzer <auriocus@gmx.de> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: Nearest neighbours of points |
| Date | 2015-10-24 22:45 +0200 |
| Organization | A noiseless patient Spider |
| Message-ID | <n0gqhc$6l1$1@dont-email.me> (permalink) |
| References | <81947104-f6dd-48b3-ba7b-f03b0c5b6f39@googlegroups.com> |
Am 24.10.15 um 22:05 schrieb Poul Riis: > 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? What makes you think that there should be a special function? I think the intent is quite clearly expressed using your code: > distances=scipy.spatial.distance.pdist(pts) > n=np.argmin(distances) Are you hoping for a speed improvement? Your algorithm is O(n^2) in the number of points n. You can probably go down to O(n*log(n)) using a space partitioning tree like a kd-tree. I can't tell whether it's worth the effort, that depends on n. Also your code is invoking two compiled functions; I doubt it could be much faster, unless the algorithm is changed. Christian
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