Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

Calculate Euclidean Distance in Python

# Python code to find Euclidean distance
# using dot() and sqrt() methods

# Import NumPy Library
import numpy as np

# initializing points in
# numpy arrays
point1 = np.array((4, 4, 2))
point2 = np.array((1, 2, 1))

# subtracting both the vectors
temp = point1 - point2
 
# Perform dot product
# and do the square root
dist = np.sqrt(np.dot(temp.T, temp))
 
# printing Euclidean distance
print(dist)
Source by itsmycode.com #
 
PREVIOUS NEXT
Tagged: #Calculate #Euclidean #Distance #Python
ADD COMMENT
Topic
Name
8+2 =