All problems
Frobenius Inner Product
Problem
Compute the Frobenius inner product of two matrices of the same shape:
<A, B> = sum_ij A[i][j] * B[i][j]
Hint
This is the dot product after flattening both matrices.
Test cases
case 1
in: [[[1,2],[3,4]],[[5,6],[7,8]]]
expected: 70
case 2
in: [[[1,2],[3,4]],[[1,0],[0,1]]]
expected: 5
case 3
in: [[[1,-1]],[[2,3]]]
expected: -1
case 4
in: [[[0]],[[5]]]
expected: 0
Starter codePython
def frobenius_inner_product(A, B):
# Your code here
pass4 test cases · run your code against them in the editor