Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Terry Reedy Newsgroups: comp.lang.python Subject: Re: Nearest neighbours of points Date: Sat, 31 Oct 2015 23:00:54 -0400 Lines: 18 Message-ID: References: <81947104-f6dd-48b3-ba7b-f03b0c5b6f39@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de ppmo0BL4Zo3Oci8RnryfdA8XLQBLhO7bhu/yXBpIe4fw== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'converts': 0.07; 'linear': 0.07; 'smallest': 0.07; 'tom': 0.07; 'indexes': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'rows': 0.09; 'stored': 0.10; 'jan': 0.11; 'index': 0.13; '10:05': 0.16; 'formula': 0.16; 'received:80.91.229.3': 0.16; 'received:io': 0.16; 'received:plane.gmane.org': 0.16; 'received:psf.io': 0.16; 'reedy': 0.16; 'symmetric': 0.16; 'triangle': 0.16; 'wrote:': 0.16; '(see': 0.20; 'gather': 0.22; 'header:In-Reply-To:1': 0.24; 'header:User-Agent:1': 0.26; 'example': 0.26; 'header:X -Complaints-To:1': 0.26; 'points': 0.27; 'point': 0.33; 'list': 0.34; 'but': 0.36; 'should': 0.36; 'depends': 0.36; 'to:addr :python-list': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'two': 0.37; 'received:org': 0.37; 'list.': 0.37; 'minimum': 0.38; 'represent': 0.38; 'to:addr:python.org': 0.40; 'upper': 0.76; 'distances': 0.84; 'matrix.': 0.84; 'distance.': 0.91; 'received:fios.verizon.net': 0.91 X-Injected-Via-Gmane: http://gmane.org/ X-Gmane-NNTP-Posting-Host: pool-173-59-124-74.phlapa.fios.verizon.net User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 In-Reply-To: X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.20+ Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:98028 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