All problems
Euclidean Distance Matrix
Problem
Given a list of points, return the full pairwise Euclidean distance matrix:
D[i][j] = ||points[i] - points[j]||_2
The matrix is symmetric with zero diagonal.
Hint
Compute each pair independently; the diagonal is always zero.
Test cases
case 1
in: [[[0,0],[3,4]]]
expected: [[0,5],[5,0]]
case 2
in: [[[1,1],[1,1]]]
expected: [[0,0],[0,0]]
case 3
in: [[[0,0],[1,0],[0,1]]]
expected: [[0,1,1],[1,0,1.4142135623730951],[1,1.4142135623730951,0]]
case 4
in: [[[0,0,0],[1,2,2]]]
expected: [[0,3],[3,0]]
Starter codePython
def distance_matrix(points):
# Your code here
pass4 test cases · run your code against them in the editor