Hello! In our last lesson, we dug into the dot product and saw how it reveals the geometric relationship between two vectors. We also briefly encountered the notation . This lesson will fully unpack that notation and generalize the dot product into one of the most powerful tools in linear algebra: matrix multiplication.
We'll cover how to perform matrix multiplication and the related transpose operation. More importantly, we'll explore why these operations are defined the way they are, connecting the mechanics to the powerful idea of composing linear transformations. This is fundamental for understanding how data flows through neural networks, a topic you're particularly interested in.
1. The Matrix Transpose
Let's start by demystifying the superscript 'T' we saw in the previous lesson. It stands for the transpose operation, which is a simple but essential way to reconfigure a matrix.
The transpose of a matrix , denoted as , is formed by swapping its rows and columns. If the original matrix has dimensions , its transpose will have dimensions . The element that was in row , column of moves to row , column of .

For example, if we have a matrix :
Its transpose is:
Now, the notation from our last lesson should be clearer. In linear algebra, vectors are typically treated as column vectors (matrices with one column). The dot product of two column vectors and is undefined under the rules of matrix multiplication. By transposing the first vector, becomes a row vector, making the multiplication possible.
Matrix Algebra - Linear Algebra for Deep Learning (Part 2)
This section from QuantStart provides a formal definition and clear examples of the transpose operation.
Read the section titled "Matrix Transpose". Pay attention to the index notation [a_{ji}] and how it applies to both matrices and vectors.
2. Matrix Multiplication: The Mechanics
At its core, matrix multiplication is a series of dot products. To find the element in the -th row and -th column of the resulting matrix, you take the dot product of the -th row of the first matrix with the -th column of the second matrix.
The Dimension Rule
A crucial rule for matrix multiplication is that the "inner" dimensions must match. If you are multiplying matrix by matrix to get , and is an matrix, then must be an matrix. The resulting matrix will have dimensions .
Rule:
If the number of columns in does not equal the number of rows in , the multiplication is undefined.
The following reading provides a fantastic visual guide to this "row-times-column" method.
A Visual Tutorial for Matrix Multiplication - Master the Math
This article offers several perspectives on matrix multiplication. We'll start with the most common one.
Read "Perspective 2: Rows × Columns Dot Products". The diagrams and the step-by-step numerical example make the process very clear. This perspective directly builds on your knowledge of the dot product from our last lesson.
3. The "Why" Behind Matrix Multiplication
Why is matrix multiplication defined in this seemingly complex way? The answer lies in its geometric meaning: matrix multiplication corresponds to the composition of linear transformations.
Imagine you apply one transformation to a vector (e.g., a rotation), and then you apply a second transformation to the result (e.g., a shear). The composition is a single new transformation that takes you from the start to the end in one step. The matrix representing this new, combined transformation is the product of the two original matrices.
This perspective is incredibly powerful and provides a deep intuition that is far more useful than just memorizing the row-by-column algorithm.
Matrix multiplication as composition | Chapter 4, Essence of linear algebra
This classic video from 3Blue1Brown, "Matrix multiplication as composition", provides the best geometric intuition for this concept.
Watch the section that explains matrix multiplication as a composition of transformations. Note the convention of reading matrix products from right to left, just like nested functions. Finally, observe the geometric explanation for why matrix multiplication is not commutative (AB \neq BA) and why it is associative ((AB)C = A(BC)).
As the video masterfully explains, applying a rotation then a shear is geometrically different from applying a shear then a rotation. This is the intuitive reason why, in general, . The order matters.
4. Matrix Operations in Neural Networks
Matrix multiplication is the engine of modern deep learning. A single layer of a neural network performs a linear transformation on its inputs, which is exactly what matrix multiplication does.
The calculation for a layer's output before the activation function is often written as:
Where:
- is the vector of inputs from the previous layer.
- is the weight matrix, containing the strengths of the connections. Each row of corresponds to a neuron in the current layer.
- is the bias vector, which is added after the multiplication.
- is the resulting vector of outputs.

The StatQuest channel provides a clear, step-by-step walkthrough of this process in a simple neural network.
Essential Matrix Algebra for Neural Networks, Clearly Explained!!!
This clip from "Essential Matrix Algebra for Neural Networks" by StatQuest connects the math directly to a machine learning application.
Watch the final segment of the video, which demonstrates how a neural network uses a sequence of matrix multiplications and additions to transform input data (petal and sepal width) into a prediction. This provides a concrete example of the concepts in action.
It's also worth noting that there is another type of matrix multiplication called the Hadamard Product (or element-wise product), denoted by . In this case, the matrices must have the same dimensions, and the result is a new matrix where each element is simply the product of the elements in the same position. While different from standard matrix multiplication, the Hadamard product also appears in some advanced ML architectures, such as LSTMs and attention mechanisms.
5. Practice Problems
Let's put this into practice. Given the following matrices:
- What are the dimensions of and ?
- Is the product defined? If so, what will its dimensions be? Calculate .
- Is the product defined? If so, what will its dimensions be? Calculate .
- What is ?
Solutions
-
is a matrix. is a matrix.
-
Yes, is defined because the inner dimensions match (3 and 3). The resulting matrix will be .
-
Yes, is also defined because the inner dimensions match (2 and 2). The resulting matrix will be .
This also clearly demonstrates that .
-
To find , we swap the rows and columns of .
Conclusion
In this lesson, we moved from the dot product to the more general operations of matrix multiplication and transpose. These are not just arbitrary rules but the language used to describe complex transformations and computations efficiently.
Key Takeaways:
- The transpose () of a matrix flips its rows and columns and is often used to make dimensions compatible for multiplication.
- Matrix multiplication is a series of dot products. The element at position of the product is the dot product of row of the first matrix and column of the second.
- The deeper meaning of matrix multiplication is the composition of linear transformations.
- Matrix multiplication is not commutative (), a direct consequence of the fact that the order of transformations matters.
- These operations are the computational backbone of neural networks, allowing us to express the transformation of data through a layer with the equation .
Now that we understand how matrices act on vectors and on each other, we are ready to explore the geometric spaces they create. In our next lesson, we will delve into the concepts of linear independence and span, which will help us understand the range of all possible outputs a transformation can produce.