All problems
Max Pooling
Problem
Apply max pooling to a 2D image.
Slide a k x k window with the given stride and take the maximum in each window. The output shape is ((H - k) // stride + 1) x ((W - k) // stride + 1).
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,10],[11,12,13,14,15],[16,17,18,19,20],[21,22,23,24,25]],3,2]
expected: [[13,15],[23,25]]
case 4
in: [[[42]],1,1]
expected: [[42]]
Starter codePython
def max_pool(image, k, stride):
# Your code here
pass4 test cases · run your code against them in the editor