@ multiplies the last two axes
The final grade weights the tests: 20% for test 1, 30% for test 2, 50% for test 3.
# one weight per test
weights = np.array([0.2, 0.3, 0.5])
print(square @ weights)
[83. 70. 74.5]
@ is matrix multiply. Here it multiplies each student's row by the weights, number by number, and adds them up. That's one final grade per student. Ana: 0.2*70 + 0.3*80 + 0.5*90 = 83.
Tap a grade to see its row of scores meet the weights:
square(3, 3)@weights(3,)→(3,)the two 3s meet, get added up, and disappearNow compare two ways of grading. Scheme A is the weights above. Scheme B counts only test 3. Put each scheme in a column:
# test 1
schemes = np.array([[0.2, 0.0],
# test 2
[0.3, 0.0],
# test 3
[0.5, 1.0]])
print(square @ schemes)
[[83. 90. ]
[70. 60. ]
[74.5 75. ]]
Each row is a student. Each column is a scheme. Entry [i, j] is student i's row times scheme j's column, added up. Ben gets 70 under scheme A and 60 under scheme B.
square(3, 3)@schemes(3, 2)→(3, 2)the two 3s meet, get added up, and disappearIn the editor, fill in schemes with one column per scheme. Scheme A is the weights above. Scheme B counts tests 2 and 3, half each. Then fill in grades with one @: one row per student, one column per scheme.