Shapes before matrix multiplication

15-minute session: read for 3 minutes, trace for 3, experiment for 7, and complete the check for 2. Spend longer whenever you need.

For A with shape m×k and B with shape k×n, the result has shape m×n. The inner dimensions must match. Check empty and ragged inputs before indexing. A shape check prevents some errors but cannot establish that the weights mean the right thing. The example is a small CPU reference, not a trained language model.

Practice and evidence: Predict the example or draw its state transitions. Change one assumption, test the boundary, and record the actual result. Explain what this small model does not establish about a production system.

a=[[1,2],[3,4]]
b=[[5],[6]]
assert all(len(row)==len(b) for row in a)
out=[[sum(a[i][k]*b[k][j] for k in range(len(b))) for j in range(len(b[0]))] for i in range(len(a))]
print(out)

Expected result: [[17], [39]]

Practice and evidence

Keep three notes: your prediction, the actual result, and why they match or differ. The completion check grades understanding; the practice task builds skill.

Language reference: git.agilaos.com

Language reference: onnx.ai