Master the Golden Axis Rule: axis=0 collapses rows (↓); axis=1 collapses columns (→).
The `axis` parameter defines which dimension to collapse during multi-dimensional aggregations. In 2D: `axis=0` moves vertically DOWN across rows; `axis=1` moves horizontally ACROSS columns.
The Golden Axis Rule: 'The axis you specify is the axis that disappears!' If you specify axis=0 (rows), rows disappear leaving column totals.
`axis=0` collapses Dimension 0 (rows ↓), producing column results. `axis=1` collapses Dimension 1 (columns →), producing row results.
col_sums = matrix.sum(axis=0); row_sums = matrix.sum(axis=1)row_sums = matrix.sum(axis=0) # Intending row sums but got column sums!row_sums = matrix.sum(axis=1)Remember: axis=0 acts along rows (downward), aggregating into column sums.
Solve the objective below using NumPy vectorized syntax
Given `mat = np.array([[10, 20], [30, 40]])`, compute column sums with `mat.sum(axis=0)` and print.
[40 60]