Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- fileName = "/home/sayem/workspace/me-workspace/notebook-test/data/sampledata.txt"
- def ReadData(fileName):
- # Read the file, splitting by lines
- with open(fileName, 'r') as f:
- f = open(fileName, 'r')
- lines = f.read().splitlines()
- f.close()
- items = []
- for i in range(0, len(lines)):
- line = lines[i].split(',')
- itemFeatures = {"x": float(line[0]), "y": float(line[1])}
- items.append(itemFeatures)
- #shuffle(items)
- return items
- def EuclideanDistance(points=[]):
- s = 0; # The sum of the squared differences of the elements
- for point in points:
- s += pow(point.get("x")-point.get("y"), 2)
- return pow(s, 1/2)
- _items = ReadData(fileName=fileName)
- EuclideanDistance(points=_items)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement