Skip to content Skip to sidebar Skip to footer

Find The Index Of The Min Value In A Pdist Condensed Distance Matrix

I have used scipy.spatial.distance.pdist(X) to calculate the euclidian distance metric between each pair of elements of the below list X: X = [[0, 3, 4, 2], [23, 5, 32, 1], [3, 4,

Solution 1:

We'll operate on the square form of the results. First, to exclude "New York is closest to New York" answers,

numpy.fill_diagonal(distances, numpy.inf)

Then, it's a simple argmin along an axis:

closest_points = distances.argmin(axis=0)

Post a Comment for "Find The Index Of The Min Value In A Pdist Condensed Distance Matrix"