Skip to content
DeepForgeby svx
All problems
EasyML Fundamentalsml-029

Euclidean Distance

Problem

Compute the Euclidean distance between two vectors: sqrt(sum((a_i - b_i)^2)).

Empty vectors return 0.0.

Hint

Sum the squared coordinate differences, then take the square root.

Test cases

case 1
in: [[3,4],[0,0]]
expected: 5
case 2
in: [[1,2,3],[4,5,6]]
expected: 5.196152422706632
case 3
in: [[-1,-1],[2,3]]
expected: 5
case 4
in: [[],[]]
expected: 0
Starter codePython
import math
def euclidean_distance(a, b):
    # Your code here
    pass

4 test cases · run your code against them in the editor