Skip to content
DeepForgeby svx
All problems
MediumLinear Algebrala-073

Gram Matrix

Problem

Compute the Gram matrix G of a list of vectors, where G[i][j] is the dot product of vectors[i] and vectors[j].

All vectors have the same length.

Hint

The Gram matrix is symmetric with the squared norms on its diagonal.

Test cases

case 1
in: [[[1,0],[0,1]]]
expected: [[1,0],[0,1]]
case 2
in: [[[1,2],[3,4]]]
expected: [[5,11],[11,25]]
case 3
in: [[[1,1,1],[1,-1,0]]]
expected: [[3,0],[0,2]]
case 4
in: [[[2],[3]]]
expected: [[4,6],[6,9]]
Starter codePython
def gram_matrix(vectors):
    # Your code here
    pass

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