Skip to content
DeepForgeby svx
All problems
MediumComputer Visioncv-189

Window Partition (Padded)

Problem

Partition an image into non-overlapping windows, padding the bottom and right with zeros to a multiple of the window size.

Return the windows in row-major order as 2D lists.

Test cases

case 1
in: [[[1,2],[3,4]],2]
expected: [[[1,2],[3,4]]]
case 2
in: [[[1,2,3],[4,5,6],[7,8,9]],2]
expected: [[[1,2],[4,5]],[[3,0],[6,0]],[[7,8],[0,0]],[[9,0],[0,0]]]
case 3
in: [[[1,2,3,4],[5,6,7,8]],2]
expected: [[[1,2],[5,6]],[[3,4],[7,8]]]
case 4
in: [[[1]],1]
expected: [[[1]]]
Starter codePython
def window_partition_padded(image, window):
    # Your code here
    pass

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