Matrix-Vector Products
A matrix-vector product combines each row of a matrix with one vector.
X @ w
If X.shape is (3, 2) and w.shape is (2,), the result has shape (3,).
Read it as:
three rows, each scored by the same two weights
For each row, multiply corresponding entries by the vector entries and add the products. The result therefore contains one number per row.
Compute scores
Three row scores
Ready to run.
Manual check for the first row:
[1, 2] dot [10, 1] = 1*10 + 2*1 = 12
So the first score is 12.
Inner dimensions must match
For:
X @ w
the number of columns in X must match the length of w.
(rows, features) @ (features,) -> (rows,)
This pattern is the foundation of linear models and neural network layers.
If X.shape is (4, 3) and w.shape is (3,), what is the shape of
X @ w?
Answer it first, then check.
Hint
Use (rows, features) @ (features,) -> (rows,).
Solution
The result shape is (4,). The matching feature dimension of length three is
combined, leaving one score for each of the four rows.