python euclidean distance 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: np euclidean distance python
import numpy as np
a = np.array((1,1,1))
b = np.array((2,2,2))
dist = np.linalg.norm(a-b)
Example 4: numpy euclidean distance
dist = numpy.linalg.norm(a-b)
Example 5: 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))
Example 6: euclidian function in python
import math
x = (5, 6, 7)
y = (8, 9, 9)
distance = math.sqrt(sum([(a - b) ** 2 for a, b in zip(x, y)]))
print("Euclidean distance from x to y: ",distance)