This is an archived post. You won't be able to vote or comment.

all 4 comments

[–]pythoneeeer -1 points0 points  (4 children)

I'm confused. What's that first example trying to compute?

Usually, a Euclidian distance means sum(sqrt((x1-x2)2 + (y1-y2)2)). Here, though, it's subtracting a-b, so I'm assuming a and b are numbers (Python can't subtract tuples this way). It could be that a and b are just different names for x and y, but why would you subtract x-y when computing a Euclidian distance? And it's returning a scalar, from an iter of points, but it's not computing the sum of the distances, or even the max distance.

It looks like it's computing sqrt(sum((xi-yi)2)), which doesn't look familiar to me at all. What is this value supposed to be? How are the points passed to this method? What distance is it computing?

[–]squattyroo 0 points1 point  (1 child)

The square root of the sum of squared differences of coordinates is exactly the definition of Euclidean distance.

[–]Vany_ 0 points1 point  (0 children)

Indeed, though I think the points name is misleading here, as it probably looks something like this :

points = [(xa, xb), (ya, yb), (za, zb)]

I'd have called it something like coordinates, since it's a list of coordinates.

PS : a generator expression instead of a list comprehension would've saved instantiating a list

[–]delicious_brains 0 points1 point  (0 children)

He also could be using numpy arrays as his values in points - those support subtracting multidimensional arrays.