0 / 34

Invite others

Progress

0 / 34

Reshape & Flatten

Change structure, keep data:

a = np.arange(12)
b = a.reshape(3, 4)
b.flatten()  # back to 1D
Why this matters

Models and file formats care about shape (batch × features, image × channels). Reshaping lets you reinterpret the same buffer: 1D sequence ↔ grid ↔ batch matrices—often without copying when the total size matches.

Confusing reshape with transpose is a common mistake; this lesson anchors the difference.

ResourcesDocs, references & more — opens in a new tab
🎯 Your Task

flat = np.arange(1,13). Reshape → grid (3,4). Flatten → back_flat.

flat.reshape(3, 4) then grid.flatten()
exercise.py
⌘⏎ run · ⌘← → nav
Output
Run your code to see output here.