0 / 34
Lesson 11

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.