Nearest neighbours of points

Terry Reedy tjreedy at udel.edu
Sat Oct 31 23:00:54 EDT 2015


On 10/31/2015 5:28 PM, Tom P wrote:
> 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

distances is conceptually a 2-d matrix, but since it would be 
symmetrical, I gather that it is stored as 1-d represention  You should 
be able to find the formula that converts the linear index to the 
indexes of the corresponding symmetric matrix.  It depends on whether 
distances represent the upper or lower triangle of the symmetric matrix 
and whether the triangular matrix is stored by rows or columns.

-- 
Terry Jan Reedy




More information about the Python-list mailing list