xxxxxxxxxx
import numpy as np
a = np.array((1,1,1))
b = np.array((2,2,2))
dist = np.linalg.norm(a-b)
xxxxxxxxxx
# I hope to be of help and to have understood the request
from math import sqrt # import square root from the math module
# the x and y coordinates are the points on the Cartesian plane
pointA = (x, y) # first point
pointB = (x, y) # second point
distance = calc_distance(pointA, pointB) # here your beautiful result
def calc_distance(p1, p2): # simple function, I hope you are more comfortable
return sqrt((p1[0]-p2[0])**2+(p1[1]-p2[1])**2) # Pythagorean theorem
xxxxxxxxxx
def euclidean_distance(row1, row2):
distance = 0.0
for i in range(len(row1)-1):
distance += (row1[i] - row2[i])**2
return m.sqrt(distance)
xxxxxxxxxx
# Python code to find Euclidean distance
# using dot()
import numpy as np
# initializing points in
# numpy arrays
point1 = np.array((1, 2, 3))
point2 = np.array((1, 1, 1))
# subtracting vector
temp = point1 - point2
# doing dot product
# for finding
# sum of the squares
sum_sq = np.dot(temp.T, temp)
# Doing squareroot and
# printing Euclidean distance
print(np.sqrt(sum_sq))