Skip to content
DeepForgeby svx
All problems
EasyComputer Visioncv-043

Constant Padding

Problem

Pad a 2D image with a constant value.

Return a new image with pad extra rows and columns of value on every side while keeping the original values in the center. pad may be 0 and value may be negative.

Test cases

case 1
in: [[[1,2],[3,4]],1,9]
expected: [[9,9,9,9],[9,1,2,9],[9,3,4,9],[9,9,9,9]]
case 2
in: [[[1,2]],1,-1]
expected: [[-1,-1,-1,-1],[-1,1,2,-1],[-1,-1,-1,-1]]
case 3
in: [[[1,2],[3,4]],0,7]
expected: [[1,2],[3,4]]
Starter codePython
def constant_pad(image, pad, value):
    # Your code here
    pass

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