8/26
Part 2 of 4 · BroadcastingLearn and do
One number per student, used for every test
Now the question from before: how far is each score below that student's best? best is the column from the keepdims section, one number per student.
scores (2, 3)test 1test 2test 3AnaBen
−
best (2, 1) stretched to (2, 3)=
result (2, 3)
test 1test 2test 3AnaBen
Ben, test 3: 60 - 100 = -40. The 100 is Ben's best.
real numbers copies NumPy acts as if it madeTap a cell to see where its numbers come from.
This time NumPy copies each student's best across that student's row:
# (2, 1): 90 for Ana, 100 for Ben
best = scores.max(axis=1, keepdims=True)
print(scores - best)
[[-20 -10 0]
[-50 0 -40]]
Ana's best is 90, so her scores drop by 90. Ben's best is 100, so his scores drop by 100.
In the editor, fill in below_best, each score minus that student's best, as printed here, and vs_test_avg, each score minus that test's average. One needs keepdims, and the other works without it. Work out which before you run it.