Manual Max Pooling
Given a 4x4 grid of numbers, apply 2x2 max pooling (stride 2) manually — the exact operation MaxPooling2D performs inside a CNN, shrinking the data while keeping only the most important value from each region.
Approach: slide a non-overlapping 2x2 window across the grid, taking the maximum value in each window to build a smaller 2x2 output grid.
Input: Four lines: the 4x4 grid, one row of 4 space-separated numbers per line.
Output: Two lines: the resulting 2x2 pooled grid, one row per line, each printed as a Python list.
1 3 2 4 5 6 7 8 3 2 1 0 1 2 3 4
[6, 8] [3, 4]
- Values are whole numbers.
Hint 1
Step through the grid in 2x2 blocks: rows 0-1 then rows 2-3, and within each, columns 0-1 then columns 2-3.
Hint 2
Each output cell is the max of the 4 values in its corresponding 2x2 input block.
Hint 3
range(0, 4, 2) gives the top-left corner (0 or 2) of each block along one axis.
Max pooling slides a non-overlapping window (here 2x2) across the input, keeping only the maximum value from each window — exactly what MaxPooling2D does inside a CNN to shrink the data while preserving its strongest detected features. Iterating the grid in steps of 2 along both axes and taking max() of each 2x2 block's 4 values builds the smaller output grid directly, in pure Python.