import euclidean distance python code example
Example 1: distance euc of two arrays python
import numpy as np
a = np.array([1.0, 3.5, -6.3])
b = np.array([4.5, 1.6, 1.2])
dist = np.linalg.norm(a-b)
Example 2: euclidean distance python
from math import sqrt
pointA = (x, y)
pointB = (x, y)
distance = calc_distance(pointA, pointB)
def calc_distance(p1, p2):
return sqrt((p1[0]-p2[0])**2+(p1[1]-p2[1])**2)
Example 3: euclidean distance python 3 variables
import numpy as np
point1 = np.array((1, 2, 3))
point2 = np.array((1, 1, 1))
sum_sq = np.sum(np.square(point1 - point2))
print(np.sqrt(sum_sq))