Skip to content
DeepForgeby svx
All problems
MediumLinear Algebrala-027

Outer Product

Problem

Compute the outer product of vectors a (length m) and b (length n).

The result is an m x n matrix C with C[i][j] = a[i] * b[j].

Hint

Every row of the result is a scaled copy of b.

Test cases

case 1
in: [[1,2],[3,4]]
expected: [[3,4],[6,8]]
case 2
in: [[1,0],[2,3,4]]
expected: [[2,3,4],[0,0,0]]
case 3
in: [[2,-1],[1,1]]
expected: [[2,2],[-1,-1]]
case 4
in: [[0,5],[7,8]]
expected: [[0,0],[35,40]]
Starter codePython
def outer_product(a, b):
    # Your code here
    pass

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