Skip to content Skip to sidebar Skip to footer

Find The Distance Of Each Pair Between Two Vectors

I have two vectors, let's say x=[2,4,6,7] and y=[2,6,7,8] and I want to find the euclidean distance, or any other implemented distance (from scipy for example), between each corres

Solution 1:

cdist does not compute the list of distances between corresponding pairs, but the matrix of distances between all pairs.

np.linalg.norm((np.asarray(x)-np.asarray(y))[:, None], axis=1)

Is how id typically write this for the Euclidian distance between n-dimensional points; but if you are only dealing with 1 dimensional points, the absolute difference, as suggested by elpres would be simpler.

Post a Comment for "Find The Distance Of Each Pair Between Two Vectors"