Most useful quantities aren't single numbers scattered across a tensor's dimensions — they're summaries: the total across a batch, the average score, the single best prediction. Reduction operations collapse many elements down to fewer, and getting the collapsed shape right (and, for max, getting more than just the value back) is where a lot of otherwise-correct-looking code quietly breaks downstream.
Implement sum_, mean_, and max_, all taking axis and keepdims. max_ is the odd one out: with axis=None it returns a single scalar like np.max, but with axis given, it must return (values, indices) — a real, distinctive difference from plain np.max.
a: any NumPy array. axis: None (reduce over everything) or an integer axis.keepdims: when True, the reduced axis stays in the shape as size 1 instead of being removed.sum_/mean_ return a plain array (or scalar when axis=None).max_ with axis=None returns a plain scalar. With axis given, it returns a 2-tuple (values, indices).a.Open one at a time. Each gives away a little more than the last.
sum_ and mean_ need nothing beyond passing axis/keepdims straight through to NumPy's own equivalents.
max_ needs a real if: axis is None behaves like plain np.max, but any other axis needs both np.max AND np.argmax called with that same axis/keepdims, returned together.
Click "Run Tests" to test your implementation