Lesson 5 of 10 · 2 min
Reshape and Flatten
import numpy as np arr = np.arange(0, 12) print(arr) # Output: [ 0 1 2 3 4 5 6 7 8 9 10 11] # Reshape to 3x4 arr_2d = arr.reshape(3, 4) print(arr_2d) # Output: # [[ 0 1 2 3] # [ 4 5 6 7] # [ 8 9 10 11]] # Flatten back to 1D arr_flat = arr_2d.flatten() print(arr_flat) # Output: [ 0 1 2 3 4 5 6 7 8 9 10 11]
