11/26
Part 2 of 4 · BroadcastingLearn

When the shapes don't fit

The third example in the rule's figure, one step back, is the flat best, the one without keepdims:

scores - scores.max(axis=1)
ValueError: operands could not be broadcast together with shapes (2,3) (2,)

The flat best is (2,). Lined up on the right, its 2 sits under the table's 3 tests. 3 and 2 are not equal, and neither is 1, so NumPy stops.

The flat best does not fitInteractive
Shapes, lined up on the right
rowscolumnsscores23scores.max(axis=1)none2checknone: stretches3 vs 2resulterror
scores (2, 3)
test 1test 2test 3Ana708090Ben5010060
−
scores.max(axis=1) (2,), lined up on the right
test 1test 2test 3?90100
=
no result
ValueError: operands could not be broadcast together with shapes (2,3) (2,)

An error is the good outcome, because it tells you something is wrong. The bad outcome is next.