All problems
Kronecker Product
Problem
Compute the Kronecker product of A (m x n) and B (p x q), producing an (m*p) x (n*q) matrix.
Block (i, j) of the result is A[i][j] * B, laid out in row-major order.
Hint
Scale each entry of A by the whole matrix B and tile the blocks.
Test cases
case 1
in: [[[1,2],[3,4]],[[0,5],[6,7]]]
expected: [[0,5,0,10],[6,7,12,14],[0,15,0,20],[18,21,24,28]]
case 2
in: [[[1,0],[0,1]],[[1,2],[3,4]]]
expected: [[1,2,0,0],[3,4,0,0],[0,0,1,2],[0,0,3,4]]
case 3
in: [[[2]],[[3]]]
expected: [[6]]
case 4
in: [[[1,1]],[[2,3]]]
expected: [[2,3,2,3]]
Starter codePython
def kronecker_product(A, B):
# Your code here
pass4 test cases · run your code against them in the editor