Advertisement
Guest User

sample.py

a guest
Jan 18th, 2020
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.81 KB | None | 0 0
  1. import sys
  2. fileName = "/home/sayem/workspace/me-workspace/notebook-test/data/sampledata.txt"
  3.  
  4. def ReadData(fileName):
  5.  
  6. # Read the file, splitting by lines
  7. with open(fileName, 'r') as f:
  8. f = open(fileName, 'r')
  9. lines = f.read().splitlines()
  10. f.close()
  11.  
  12. items = []
  13.  
  14. for i in range(0, len(lines)):
  15. line = lines[i].split(',')
  16. itemFeatures = {"x": float(line[0]), "y": float(line[1])}
  17.  
  18. items.append(itemFeatures)
  19.  
  20. #shuffle(items)
  21.  
  22. return items
  23.  
  24. def EuclideanDistance(points=[]):
  25. s = 0; # The sum of the squared differences of the elements
  26. for point in points:
  27. s += pow(point.get("x")-point.get("y"), 2)
  28. return pow(s, 1/2)
  29.  
  30. _items = ReadData(fileName=fileName)
  31. EuclideanDistance(points=_items)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement