简体   繁体   中英

Scipy Euclidean distance between two points

The below code for calculating the Euclidean distance between two points returns [[9.]] :

from scipy import spatial
d1 = [[11 , 3]]
d2 = [[2 , 3]]
print(spatial.distance.cdist(d1 , d2 ,  "euclidean"))

But the Euclidean distance between these two points is 3?

Has the Euclidean distance been implemented correctly?

The formula for Euclidean distance is the following: dist((x, y), (a, b)) = √((x - a)² + (y - b)²)

Which gives: = √((11 - 2)² + (3 - 3)²) = √(9)² = 9

The Distance is 9. Euclidian distance is root of sum of squared differences . So you have sqrt( (11-2)^2 ) which is sqrt( 9^2 ) which is 9

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM