-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQT_tests.py
More file actions
49 lines (36 loc) · 1.18 KB
/
QT_tests.py
File metadata and controls
49 lines (36 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env python3
##Libraries
import sys
print(len(sys.argv))
if len(sys.argv) == 2:
infile = sys.argv[1]
else:
infile = "data/point1000.lst"
##Functions
#loading data
def readpoints(infile):
point_list = []
with open(infile) as file:
for line in file:
line = line.strip().split()
point_list.append((line[0],[float(n) for n in line[1:]]))
return(point_list)
print(readpoints(infile))
point_data = readpoints(infile)
import math
def euclidean_dist(pointA, pointB):
"""Takes two points as input and calculates the euclidean distance between them"""
# Start a square sum
square_sum = 0
# Loop through the point values, and measure the square sum of the differences
for i in range(len(pointA[1])):
square_sum += (pointA[1][i]- pointB[1][i])**2
# Get the euclidean distance
distance = math.sqrt(square_sum)
return distance
distance_matrix = {}
for i in range(len(point_data)):
for j in range(i + 1, len(point_data)):
dist = euclidean_dist(point_data[i], point_data[j])
distance_matrix[(i, j)] = dist
#print(distance_matrix)