Skip to content
DeepForgeby svx
All problems
EasyLinear Algebrala-143

Batch Row Dot Products

Problem

Compute the dot product of each corresponding pair of rows of A and B.

Return a list where entry i is sum_j A[i][j] * B[i][j]. A and B must have the same shape.

Hint

This is a row-wise generalization of the vector dot product.

Test cases

case 1
in: [[[1,2],[3,4]],[[5,6],[7,8]]]
expected: [17,53]
case 2
in: [[[1,2],[3,4]],[[1,0],[0,1]]]
expected: [1,4]
case 3
in: [[[1,-1]],[[-1,1]]]
expected: [-2]
case 4
in: [[[0,0],[2,3]],[[5,5],[1,1]]]
expected: [0,5]
Starter codePython
def row_dot_products(A, B):
    # Your code here
    pass

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