PIXELBANKv9.1.0
Menu

Euclidean Distance for Face Embeddings

You are given two face embeddings (vectors) and need to calculate the Euclidean distance between them.

Face recognition systems convert face images to fixed-length vectors (embeddings). Similar faces produce similar embeddings, so the distance between embeddings indicates how similar two faces are.

The Euclidean distance (L2 distance) is:

d(a,b)=∑i=1n(ai−bi)2=∥a−b∥2d(a, b) = \sqrt{\sum_{i=1}^{n} (a_i - b_i)^2} = \|a - b\|_2

Lower distance = more similar faces.

Typical thresholds: distance < 0.6 might indicate same person, distance > 1.0 likely different people.

Example:

Input:
a = [1, 0, 0]
b = [0, 1, 0]
Output:
1.4142
Reasoning:

Computing component-wise squared differences:

  • (1-0)² = 1
  • (0-1)² = 1
  • (0-0)² = 0

Sum = 1 + 1 + 0 = 2 Distance = √2 = 1.4142

These vectors are at 90° to each other (orthogonal).

Constraints:

  • a and b are lists of floats (embeddings) of the same length
  • Return distance rounded to 4 decimal places
solution.py

Test Results

0/0
Run code to see test results.
Euclidean Distance for Face Embeddings - Easy | PixelBank