Skip to content

Instantly share code, notes, and snippets.

@jaraujoduarte
Last active May 14, 2020 12:47
Show Gist options
  • Select an option

  • Save jaraujoduarte/f84fbeecb39b19ba8f4d33c0829d7598 to your computer and use it in GitHub Desktop.

Select an option

Save jaraujoduarte/f84fbeecb39b19ba8f4d33c0829d7598 to your computer and use it in GitHub Desktop.
Average distance between points
from math import pow, sqrt
def distance_two_points(x1, y1, x2, y2):
return sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2))
points = [(1, 2), (3, 4), (5, 6)]
sum = 0
for outer_i in range(len(points)):
for inner_i in range(len(points)):
if inner_i != outer_i:
sum += distance_two_points(*points[outer_i], *points[inner_i])
average_distance = sum/len(points)
print(average_distance)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment