Broadcasting and aggregates
Aggregates such as sum, mean, max and argmax collapse an array. The axis argument picks the direction that disappears.
import numpy as np
m = np.array([[1., 2.], [3., 4.]])
print(m.sum()) # 10.0
print(m.sum(axis=0)) # columns: [4. 6.]
print(m.sum(axis=1)) # rows: [3. 7.]Broadcasting
Operations between different shapes work when, reading from the last dimension, each pair of sizes is equal or one of them is 1. The size-1 side is stretched.
print(m - m.mean(axis=0))
print(m.sum(axis=1, keepdims=True))m.mean(axis=0) has shape (2,), which lines up with columns, so each column has its own mean subtracted.
To work per row, you need shape (2, 1). keepdims=True keeps the collapsed axis as size 1, so the result broadcasts against rows correctly.
Your task
Write center_columns(m) subtracting each column's mean from that column. Write row_shares(m) dividing each row by its own sum, leaving all-zero rows as zeros. Write best_column(m) returning the index of the column with the largest total, as an int.
The explanation opens here once every check passes.