5/26
Part 1 of 4 · Shapes and axesLearn and do

keepdims keeps the axis, with size 1

Here's the next question: how far is each score below that student's own best? To answer it, each student's best has to sit next to that student's row.

best = scores.max(axis=1)
print(best)
print(best.shape)
[ 90 100]
(2,)

That's the two best scores in a flat list. The list has lost track of which row each number came from. Ask for keepdims=True and the axis stays, with length 1:

best = scores.max(axis=1, keepdims=True)
print(best)
print(best.shape)
[[ 90]
 [100]]
(2, 1)

Same two numbers. Now they stand in a column, one per row, beside the row they belong to.

Turn keepdims on and off, and watch where the two best scores go.

max along axis 1, with and without keepdimsInteractive
scores.max(axis=1)
test 1test 2test 3AnaBen
max, a flat list of 2
shape(2, 3)→(2,)the 3 tests are gone
Ana: max(70, 80, 90) = 90. In the flat list, nothing says which row this came from.

The next part shows why the column matters.

In the editor, write row_max(scores): each row's largest number, kept as a column. Reduce over axis=-1, the last axis, so a stack of tables works too.