I am working with a list of points [(1,2),(3,4),(5,6),(7,8)]. I want to find the euclidean distance from each point to every other point in the list.
I then need a new list created to represent each point in the original list, and in the new list I will add the distances relating to that point only.
So far I have:
for i in mat_ary1:
points_dist_i = []
for j in i:
row = []
x2 = [u[0] for u in i]
y2 = [u[1] for u in i]
# Calculate the distance from point j to all others
for a in x2:
dist_x_1 = pow((a - j[0]),2)
for b in y2:
dist_y_1 = pow((b - j[1]),2)
dist_xy_1 = float('{0:.2f}'.format((math.sqrt(dist_x_1 + dist_y_1))))
for item in j:
if item not in row:
row.append(dist_xy_1)
else:
continue
points_dist_i.append(row)
Each i in mat_ary1 represents a list of points. With the loops I am using I appear to repeating the same calculations.
My input seems to be duplicating the rows:
[[6.32, 6.32], [6.32, 6.32], [0.0, 0.0], [0.0, 0.0]]
[[11.4, 11.4], [11.4, 11.4], [0.0, 0.0], [0.0, 0.0]]
[[16.49, 16.49], [16.49, 16.49], [0.0, 0.0], [0.0, 0.0]]
[[14.32, 14.32], [14.32, 14.32], [0.0, 0.0], [0.0, 0.0]]
[[13.0, 13.0], [13.0, 13.0], [0.0, 0.0], [0.0, 0.0]]
[[11.66, 11.66], [11.66, 11.66], [0.0, 0.0], [0.0, 0.0]]
(1, 2)and(3, 4). for those two points you want to find the distance between1and3. And2and4?