← Problems7. Euclidean Distance
EasyVectorsLinear AlgebraDistance Metrics
Given two vectors a and b in Rn, compute the Euclidean distance between them.
d(a,b)=∑i=1n(ai−bi)2=∥a−b∥2
This is the L2 norm of the difference vector and is the most common distance metric in ML — used in k-NN, k-means, and similarity search.
Example
a = [0, 0], b = [3, 4]
Output: 5.0 # classic 3-4-5 right triangle
Constraints
- Both inputs will always have the same length.
- Return a Python
float.