P2-3.3 What Does Matrix Multiplication Reuse?¶
Section ID:
P2-3.3Version:v2026.09.08
Matrix multiplication looks at first like a simple multiplication rule, but in practice it is closer to a calculation that reuses the same weighted-sum pattern many times.
- Bundle input values together with weights and add them.
- Make one new value.
- Repeat the same calculation for several outputs.
- Apply it to several inputs at once.
Weighted Sums and Dimension Requirements¶
| Criterion | Why it matters |
|---|---|
| Matrix multiplication reuses weighted sums | Because it is the basic calculation that can create not only one output, but several outputs at once. |
| Shape decides whether the calculation is possible | Because if the inner dimensions do not match, we cannot decide which value corresponds to which weight. |
| Linear transformation changes representation | Because explanations of neural-network layers and classifiers all continue into calculations that turn an input into a new representation. |
Element-Wise and Matrix Multiplication¶
In P2-3.1, we said that vectors or matrices with the same shape can be added position by position. Multiplication can also be written as element-wise multiplication.
Here, \(\odot\) marks multiplication of values at the same positions. This calculation processes each position separately.
Matrix multiplication is different. Matrix multiplication is not a calculation that multiplies only matching positions. It creates new values by combining a row from one side with a column from the other.
- Element-wise multiplication multiplies matching positions.
- Matrix multiplication multiplies and adds by matching rows and columns.
We need to separate these two first. If matrix multiplication is misunderstood as element-wise multiplication, we misread both shape errors and the meaning of the calculation.
A Weighted Sum and One Output¶
First, think about one vector and one set of weights.
If we multiply matching positions and then add them, one number comes out.
This calculation can be read as follows.
- Multiply the first input value by the first weight.
- Multiply the second input value by the second weight.
- Add the results.
- Make one output value.
This is the basic form of a weighted sum.
In AI models, input values do not always carry the same importance. Some values can be reflected strongly, some weakly, and some in a negative direction. A weight expresses this degree of influence as a number.
Weighted Sums for Multiple Outputs¶
To make one output, we needed one weight vector. If we want to make two outputs, we need two weight vectors.
Here, \(W\) is a weight matrix. The first column can be read as the weights for making the first output value, and the second column as the weights for making the second output value.
When calculated, it becomes the following.
This calculation has reused the weighted sum twice.
Matrix multiplication repeatedly applies the small calculation multiply and add to several outputs. That is why matrix multiplication becomes a tool for turning one input vector into an output vector of another shape. In this example, the input vector has length 2, the weight matrix has shape (2, 2), and the output vector also has length 2.
Input Length and Matrix Row Count¶
In matrix multiplication, shape is extremely important. The number of values in the input vector must match the number of rows of the weight matrix.
In this calculation, the input vector has length 2 and the matrix also has 2 rows. So each input value can correspond to the weights in each row.
By contrast, the following calculation does not match immediately.
The input has 3 values, but the weight matrix has a shape that can receive only 2 inputs.
- The input length and the input-side size of the weight matrix must match.
- If they do not match, we cannot decide which value should be multiplied with which weight.
This is one reason shape errors appear so often in AI code. Matrix multiplication is, both mathematically and in code, a calculation that can run only when the shapes match.
Batch Calculation of Multiple Inputs¶
The power of matrix multiplication is not only in handling one input. We can gather several inputs into a matrix and calculate them at once.
For example, suppose we have two input vectors.
Each row is one input sample.
Now multiply by the same weight matrix \(W\).
The calculation result becomes:
The first row is the output of the first sample, and the second row is the output of the second sample.
- Gather several input samples into a matrix.
- Multiply by the same weight matrix.
- Obtain several output samples at once.
This connects to the basic intuition of batch calculation. A model can process inputs one by one, but if several inputs are bundled and calculated at once, the same calculation structure can be reused repeatedly.
Linear Transformations and Output Dimensions¶
Linear transformation can first be understood as a calculation that changes one vector into another by multiplying by a matrix.
- Prepare the input vector.
- Apply the weight matrix.
- Obtain the output vector.
For example, if the input has 2 values and the output has 3 values, the weight matrix must have a shape that can receive 2 inputs and produce 3 outputs.
This can be read as follows.
- Receive an input represented by 2 values.
- Change it into an output represented by 3 values.
In two dimensions, this change can be seen in a drawing. The following example shows an input vector \(\mathbf{x} = [2,\ 3]\) multiplied by a simple matrix \(W\), moving to \(\mathbf{y} = [2,\ 4]\).
The transformation in the figure keeps the first coordinate and changes the second from 3 to 4.
In actual AI models, this kind of transformation happens in far more dimensions than a 2D picture. So it is hard for a person to draw directly, but the basic way of thinking stays the same. An input representation moves into another representation as it passes through a weight matrix.
This perspective matters in AI. A model does not leave the input representation as it is. It changes it through several stages of calculation into another representation.
- There is an original input representation.
- It passes through the first transformation.
- We obtain an intermediate representation.
- It passes through the next transformation.
- It moves toward a representation closer to the final output.
The layers of a neural network can be seen as a structure that stacks these transformations several times. Of course, a real neural network is not made only of linear transformations. Other calculations such as activation functions, normalization, and attention also appear together.
Checklist¶
- Can you distinguish matrix multiplication from element-wise multiplication?
- Can you explain weighted sum as a calculation that multiplies input values by weights and adds them?
- Can you read matrix multiplication as a way of calculating several weighted sums at once?
- Can you explain that the length of the input vector must match the input-side size of the weight matrix?
- Can you explain the intuition of batch calculation, where several samples are bundled into a matrix and the same weight matrix is applied?
- Can you explain linear transformation as a calculation that changes an input representation into another output representation?
- Can you explain why matrix multiplication reappears in neural-network layers, embeddings, and classification?
-
Can you explain matrix multiplication as the reusable weighted-sum structure of
input -> weight matrix -> output? -
Can you read input dimension, output dimension, and weight matrix shape together and distinguish matrix multiplication from element-wise multiplication?
Sources and References¶
- Marc Peter Deisenroth, A. Aldo Faisal, Cheng Soon Ong, Mathematics for Machine Learning, Cambridge University Press, 2020, checked 2026-07-19.
- Ian Goodfellow, Yoshua Bengio, Aaron Courville, Deep Learning, MIT Press, 2016, checked 2026-07-19.
- Charles R. Harris et al., Array Programming with NumPy, Nature, 2020, checked 2026-07-19.
- NumPy Developers, numpy.matmul, NumPy User Guide, checked on 2026-07-19. This official reference supports the shape condition of matrix multiplication and the meaning of the
@operator. - Google for Developers, Neural networks: Nodes and hidden layers, Machine Learning Crash Course, checked on 2026-07-19. This official educational reference explains that neural-network node values are calculated by summing products of inputs and weights.