numpy distance between points 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: numpy euclidean distance
dist = numpy.linalg.norm(a-b)
Example 4: 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)