Let x1 y1109 and x2 y241 then x2-x12 10-42 62 36 and y2-y12 9-12 82 64 now 64 36 100 and 100 is square root of 10 sp distance between 109 and 41 is 10. Euclidean distance is the most used distance metric and it is simply a straight line distance between two points. Import functions import numpy as np from numpylinalg import norm define two vectors a nparray 2 6 7 7 5 13 14 17 11 8 b nparray 3 5 5 3 7 12 13 19 22 7 calculate Euclidean distance between the two vectors norm a-b 12409673645990857.
It details the use of the Haversine formula to calculate the distance in kilometers.
Import math p1 4 0 p2 6 6 distance mathsqrt p10-p202p11-p212 printdistance Sample Output. Sample Solution- Python Code. We will use the distance formula derived from Pythagorean theorem. Let x1 y1109 and x2 y241 then x2-x12 10-42 62 36 and y2-y12 9-12 82 64 now 64 36 100 and 100 is square root of 10 sp distance between 109 and 41 is 10.