I've been trying to get mediana from this list which means the list that has shortest Euclidean distance.
I have made a function euclid that returns the distance between 2 vectors regardless of their size, but I have a problem with 2 for loops.
This program should return [1,2,3]
xs=[[1, 1, 1], [3, 2, 1], [1, 0, 3], [1, 2, 3], [4, 4, 4]]
naj = 0
vsota=0
ys=[]
for i,j in enumerate(xs):
for x,y in enumerate(xs):
if j!=y:
vsota=euclid(j,y)
print(vsota," ",j,y)
but it currently returns:
2.23606797749979 [1, 1, 1] [3, 2, 1]
2.23606797749979 [1, 1, 1] [1, 0, 3]
2.23606797749979 [1, 1, 1] [1, 2, 3]
5.196152422706632 [1, 1, 1] [4, 4, 4]
2.23606797749979 [3, 2, 1] [1, 1, 1]
3.4641016151377544 [3, 2, 1] [1, 0, 3]
2.8284271247461903 [3, 2, 1] [1, 2, 3]
3.7416573867739413 [3, 2, 1] [4, 4, 4]
2.23606797749979 [1, 0, 3] [1, 1, 1]
3.4641016151377544 [1, 0, 3] [3, 2, 1]
2.0 [1, 0, 3] [1, 2, 3]
5.0990195135927845 [1, 0, 3] [4, 4, 4]
2.23606797749979 [1, 2, 3] [1, 1, 1]
2.8284271247461903 [1, 2, 3] [3, 2, 1]
2.0 [1, 2, 3] [1, 0, 3]
3.7416573867739413 [1, 2, 3] [4, 4, 4]
5.196152422706632 [4, 4, 4] [1, 1, 1]
3.7416573867739413 [4, 4, 4] [3, 2, 1]
5.0990195135927845 [4, 4, 4] [1, 0, 3]
3.7416573867739413 [4, 4, 4] [1, 2, 3]
How do I sum up all the numbers that start with [1,1,1], [3,2,1]...etc and then compare the distances with each and then return the index with the lower sum?