All problems
Convolution Matrix Build
Problem
Build the n x n lower-triangular Toeplitz matrix that performs causal convolution with the given kernel:
C[i][j] = kernel[i - j] when 0 <= i - j < len(kernel), else 0.
Hint
Each column of the convolution matrix is a shifted copy of the kernel.
Test cases
case 1
in: [[1,2],3]
expected: [[1,0,0],[2,1,0],[0,2,1]]
case 2
in: [[1],2]
expected: [[1,0],[0,1]]
case 3
in: [[1,2,3],3]
expected: [[1,0,0],[2,1,0],[3,2,1]]
case 4
in: [[2,0,1],4]
expected: [[2,0,0,0],[0,2,0,0],[1,0,2,0],[0,1,0,2]]
Starter codePython
def convolution_matrix(kernel, n):
# Your code here
pass4 test cases · run your code against them in the editor