Implement max pooling — the standard downsampling operation in CNNs. A sliding window takes the maximum value in each window, reducing spatial dimensions while retaining the strongest activations.
For each pooling window of size pool_size × pool_size, output the maximum value across all spatial positions (per channel).
Signature: def maxpool2d(x, pool_size=2, stride=2)
x: (H, W, C) — input feature map, channels-lastpool_size: int — pooling window size (default 2)stride: int — step between windows (default 2)output of shape (H_out, W_out, C) where H_out = (H - pool_size) // stride + 1.The test harness checks the pooled output values.
Math
Asked at
import numpy as np
def maxpool2d(...):
pass
Premium problem
Free accounts include problems #1–20. Upgrade to unlock the editor, hidden test cases, and reference solutions for every problem.
Already premium?