import numpy as np
values = np.arange(1, 13)
model_scores = np.array(
[
[0.81, 0.77, 0.79],
[0.86, 0.83, 0.85],
[0.88, 0.84, 0.87],
]
)
left_block = np.array([[1, 2], [3, 4]])
right_block = np.array([[5, 6], [7, 8]])7 NumPy Shapes And Aggregations
This notebook focuses on reshape, flatten, axis-based summaries, and stacking.
7.1 Exercise 1
Reshape values into a (3, 4) array.
# TODO: Reshape the 1D array into a 3x4 grid.
grid = values.reshape(__, __)
grid7.2 Exercise 2
Flatten the reshaped grid back into one dimension.
# TODO: Convert the grid back to a flat array.
flat_values = grid.____()
flat_values7.3 Exercise 3
Compute the mean score for each column of model_scores.
# TODO: Aggregate across rows so one mean remains per column.
column_means = model_scores.mean(axis=__)
column_means7.4 Exercise 4
Compute the maximum score within each row of model_scores.
# TODO: Keep one maximum value per row.
row_maxima = model_scores.max(axis=__)
row_maxima7.5 Exercise 5
Stack left_block and right_block vertically.
# TODO: Combine the blocks by rows.
combined = np.vstack([__________, __________])
combined