All problems
Average Pooling
Problem
Apply average pooling to a 2D image.
Slide a k x k window with the given stride and write the mean of each window, rounded to 4 decimal places. 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: [[3.5,5.5],[11.5,13.5]]
case 2
in: [[[1,2,3],[4,5,6],[7,8,9]],2,1]
expected: [[3,4],[6,7]]
case 3
in: [[[1,2],[3,4]],2,2]
expected: [[2.5]]
Starter codePython
def avg_pool(image, k, stride):
# Your code here
pass3 test cases · run your code against them in the editor