Skip to content
DeepForgeby svx
All problems
MediumDeep Learningdl-024

Max Pooling Forward

Problem

Forward pass of 2D max pooling over a square matrix using a k x k window and the given stride, without padding.

The signature is max_pool(x, k, stride). The output size per dimension is (n - k) // stride + 1.

Hint

Initialize the running maximum from the window's top-left element, not from zero.

Test cases

case 1
in: [[[1,2,3,4],[5,6,7,8],[9,10,11,12],[13,14,15,16]],2,2]
expected: [[6,8],[14,16]]
case 2
in: [[[1,2,3],[4,5,6],[7,8,9]],2,1]
expected: [[5,6],[8,9]]
case 3
in: [[[1,2,3],[4,5,6],[7,8,9]],3,3]
expected: [[9]]
case 4
in: [[[-1,-2],[-3,-4]],2,2]
expected: [[-1]]
Starter codePython
def max_pool(x, k, stride):
    # Your code here
    pass

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