-2

I'm fairly new to python so I hope somebody can help me. we have two arrays X and Y

X=np.array([[ 5.43840675, -1.05259078, -0.21793506,  8.56686818, -2.58056957,
        -0.07310339, -0.31181501,  0.02696586],
       [ 5.72318296, -0.99665473, -0.14540062,  8.32051008, -3.36201189,
        -0.04897565, -0.34271698, -0.0339766 ]])

Y=np.array([[ 5.72318296, -0.99665473, -0.14540062,  8.32051008, -3.36201189,
        -0.04897565, -0.34271698, -0.0339766 ],
       [ 5.43840675, -1.05259078, -0.21793506,  8.56686818, -2.58056957,
        -0.07310339, -0.31181501,  0.02696586]])

I was interested in calculating Euclidean distance of two numpy arrays (X and Y). for example the distance between X[1], Y[0] should be zero since there is no difference between those vectors.

X[1]=[ 5.72318296, -0.99665473, -0.14540062,  8.32051008, -3.36201189, -0.04897565, -0.34271698, -0.0339766 ] is equal to 
Y[0]=[ 5.72318296, -0.99665473, -0.14540062,  8.32051008, -3.36201189, -0.04897565, -0.34271698, -0.0339766 ]

I need to get this idea to work so if anyone can show me what I need to do to get this to work I would really appreciate it.

Man.utd
  • 59
  • 7

1 Answers1

1

based on the Euclidean distance formula:

import math
x = [ 5.72318296, -0.99665473, -0.14540062,  8.32051008, -3.36201189, -0.04897565, -0.34271698, -0.0339766 ]
y = [ 5.72318296, -0.99665473, -0.14540062,  8.32051008, -3.36201189, -0.04897565, -0.34271698, -0.0339766 ]
Index = 0
sum = 0
while Index < len(x):
    sum += (x[Index] - y[Index]) ** 2
    Index += 1
print(math.sqrt(sum))
pooya
  • 155
  • 6