1

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?

iacob
  • 20,084
  • 6
  • 92
  • 119
blue-sky
  • 51,962
  • 152
  • 427
  • 752

2 Answers2

2

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

iacob
  • 20,084
  • 6
  • 92
  • 119
Stef van der Zon
  • 633
  • 4
  • 13
1

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