Advertisement
gauravssnl

EuclideanDistance.py

Apr 27th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.38 KB | None | 0 0
  1. # distance.py by gauravssnl
  2. # find Euclidian distance
  3.  
  4. from math import sqrt
  5.  
  6. def distance(x,y):
  7.     return sqrt( sum( ( x[i] - y[i] )**2 for i in range(len(x)) ) )
  8.  
  9. def main():
  10.     x = [-9,1,10,-1,1]
  11.     y = [-5 ,9 , 6, 7,4]
  12.     print( distance(x,y))
  13.    
  14.     x = range(1,11)
  15.     y = range(10,21)
  16.     print( distance(x,y))
  17.  
  18. if __name__ == "__main__":
  19.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement