Complete worked example
python
import numpy as np
def inspect_example(rows):
data = np.asarray(rows, dtype=np.float64)
if data.ndim != 2 or 0 in data.shape or not np.isfinite(data).all():
raise ValueError("expected a non-empty finite matrix")
return data.sum(axis=0, keepdims=True)- Reasoning
- The function validates a finite, non-empty matrix and calls sum(axis=0, keepdims=True). For three observations with two features, it returns one row and two columns. Trace the additions for each column independently before running the code. A single-column input is included so that the difference between column totals and the number of observations remains visible. Reductions have operation-specific rules. Sum has an additive identity for empty input, while a mean of an empty population has no observed denominator. This lesson rejects empty matrices at its boundary rather than presenting every reduction as having the same empty-data behavior.