All problems
Zero Padding
Problem
Pad a 2D image with a border of zeros.
Return a new image with pad extra rows and columns of zeros on every side, keeping the original values in the center. pad may be 0.
Hint
Prepend and append zero rows, and wrap each original row with pad zeros.
Test cases
case 1
in: [[[1,2],[3,4]],1]
expected: [[0,0,0,0],[0,1,2,0],[0,3,4,0],[0,0,0,0]]
case 2
in: [[[5]],2]
expected: [[0,0,0,0,0],[0,0,0,0,0],[0,0,5,0,0],[0,0,0,0,0],[0,0,0,0,0]]
case 3
in: [[[1,2]],0]
expected: [[1,2]]
Starter codePython
def zero_pad(image, pad):
# Your code here
pass3 test cases · run your code against them in the editor