2-D Max Pooling

medium
Unit 3 · CNNs0/2 to milestone

Max pooling shrinks feature maps in CNNs by keeping the largest value in each window.

Implement max_pool2d(x, kernel, stride=None):

  • x has shape (channels, height, width).
  • kernel is the window size (square). stride defaults to kernel.
  • No padding: only windows that fit entirely inside the input are used, so the output height is ⌊(H−k)/s⌋+1\lfloor (H - k) / s \rfloor + 1 (same for width).
  • Return shape (channels, out_h, out_w). Pool each channel independently.

Example

max_pool2d(np.array([[[1, 2, 5, 6], [3, 4, 7, 8], [9, 1, 2, 3], [4, 5, 0, 1]]]), 2)
# array([[[4, 8], [9, 3]]])
#cnn#numpy2 visible + 2 hidden tests
solution.py · Python 3.13
Loading editor…
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
2-D Max Pooling · TechGradify