16/26
Part 3 of 4 · Picking entries out of a tableLearn and do

None adds an axis of size 1

Which students beat which, on average? That's every student against every student, so the answer is a 3 by 3 table.

# one average per student
avg = square.mean(axis=1)
print(avg)
print(avg[:, None] > avg[None, :])
[80. 70. 75.]
[[False  True  True]
 [False False False]
 [False  True False]]

None in the brackets adds an axis of size 1 at that spot. avg[:, None] turns the averages into a column (3, 1). avg[None, :] turns them into a row (1, 3). Comparing a column with a row stretches both, so every pair gets compared:

A column against a rowInteractive
Shapes, lined up on the right
rowscolumnsavg[:, None]31avg[None, :]13check1 stretches1 stretchesresult33
avg[:, None] (3, 1) stretched to (3, 3)
vs Anavs Benvs CalAnaBenCal
>
avg[None, :] (1, 3) stretched to (3, 3)
=
result (3, 3)
vs Anavs Benvs CalAnaBenCal
Ben, vs Cal: 70 > 75 is False. The 70 is Ben's average. The 75 is Cal's average.
real numbers copies NumPy acts as if it madeTap a cell to see where its numbers come from.

Row i, column j answers one question: did student i's average beat student j's?

Ana beat Ben and Cal. Cal beat Ben. Ben beat nobody.

In the editor, fill in gaps: row i, column j holds student i's average minus student j's. gaps[0, 1] should be 10, Ana's 80 minus Ben's 70.