Introduction
Welcome to your second lesson on Linear Algebra for Machine Learning. In the previous lesson, we established the fundamental building blocks: vectors. You learned how to represent data as vectors and perform essential operations like addition, scalar multiplication, and the dot product. These operations allow us to combine and compare data points.
Today, we move from manipulating individual vectors to transforming them. This lesson focuses on the learning outcome: to multiply matrices and vectors. We will explore how a matrix is not just a grid of numbers, but a powerful operator that can rotate, scale, and shear vectors and even entire spaces of data. This concept of transformation is at the very heart of how complex AI models, like neural networks, process information layer by layer.
Understanding this will provide a critical insight for your "Tony Stark" goal: you'll see how abstract mathematics provides the tools to systematically manipulate data, forming the basis for intelligent systems.
1. The Core Idea: Matrices as Transformations
Before we jump into the mechanics of multiplication, it's crucial to build a strong mental model of what matrix multiplication does. The most powerful way to think about a matrix is as a function that performs a linear transformation. It takes an input vector and produces an output vector, effectively moving it to a new location in space.

What makes a transformation "linear"? Visually, it's a transformation that keeps grid lines parallel and evenly spaced, and the origin stays put. To see this in action and understand how this geometric idea connects to the numbers in a matrix, let's watch one of the most insightful videos on the topic.
Linear transformations and matrices | Chapter 3, Essence of linear algebra
This video from 3Blue1Brown's 'Essence of linear algebra' series provides the core intuition for this entire lesson. It explains what a linear transformation is and how a matrix is simply a package of information that describes one.
Watch the video from the beginning until 08:00. Pay very close attention to this key sequence of ideas: A transformation is like a function that moves vectors. A linear transformation is fully determined by where the basis vectors (i-hat and j-hat) land. The coordinates of where these basis vectors land become the columns of the matrix. This is the central concept connecting the geometry to the numbers.
The crucial takeaway from the video is this: the product of a matrix and a vector , written as , is the resulting vector after applying the linear transformation described by to .
2. Matrix-Vector Multiplication: Two Perspectives
Now that we have the conceptual foundation, let's look at the two main ways to compute the product . Both give the same result but offer different insights.
Perspective 1: A Linear Combination of Columns
This perspective flows directly from the 3Blue1Brown video. If the columns of matrix represent the transformed basis vectors, then the product is simply a linear combination of those columns, where the components of vector act as the scalars (the weights).
In the previous lesson, you learned that a linear combination is a sum of scaled vectors, like . Matrix-vector multiplication is exactly that.
Let's say has columns and has components . Then:

This view is incredibly powerful for understanding what a matrix "does" to a vector.
Perspective 2: The Row-Column Dot Product
This is the standard, mechanical method taught in most textbooks. It's less intuitive but essential for computation by hand and for understanding the structure of the calculation.
To get the i-th element of the resulting vector, you compute the dot product of the i-th row of the matrix with the column vector .
Let's solidify both perspectives with a clear, visual guide.
A Visual Tutorial for Matrix Multiplication
This article, 'A Visual Tutorial for Matrix Multiplication', provides excellent step-by-step guides for different ways to view multiplication. We'll focus on the first two perspectives for now.
Read 'Perspective 1: Columns of A, Weighted by Entries of b' and 'Perspective 2: Rows × Columns Dot Products'. For Perspective 1, connect it directly to the 3Blue1Brown video. For Perspective 2, recognize this as the standard computational recipe. Work through the numerical examples provided for both.
Before moving on, make sure you can answer:
- If I give you a 2x2 matrix and a 2D vector, can you calculate the result using the linear combination of columns?
- Can you calculate the same result using the row-column dot product method?
3. Matrix-Matrix Multiplication: Composing Transformations
What happens when we multiply two matrices, ?
Conceptually, this corresponds to composing two linear transformations. First, you apply the transformation of , and then you apply the transformation of to that result. For example, could be a rotation, and could be a shear. The product matrix is a new, single matrix that represents the net effect of doing the rotation then the shear.
This gives us an intuitive way to calculate the product, which builds directly on what we just learned.
Perspective 3: A Matrix Acting on Columns
We can view the matrix as a collection of column vectors. The product is found by multiplying the matrix with each column of individually. The resulting vectors become the columns of the new matrix .
If , then:
Each is a standard matrix-vector multiplication, which you already know how to do.
Of course, the standard row-column dot product method also extends to matrix-matrix multiplication. The entry in the i-th row and j-th column of the product matrix is the dot product of the i-th row of and the j-th column of .
Let's see how this works in practice.
A Visual Tutorial for Matrix Multiplication
We'll now look at how to extend our understanding to matrix-matrix multiplication using the same visual tutorial, and then see the implementation in Python.
Read 'Perspective 3: Matrix × Columns (Column-by-Column Transformation)'. Notice how this is just a repeated application of matrix-vector multiplication. This is the most intuitive bridge from the previous section.
Now let's see the standard calculation and the implementation in NumPy.
2.2 Multiplying Matrices and Vectors
This blog post, based on the Deep Learning Book, provides concise examples of both the mathematical formulas and the corresponding NumPy code.
First, read 'Example 2. Multiplication of two matrices.' This demonstrates the standard row-column dot product method for a 4x3 matrix and a 3x2 matrix. Trace the calculation for one or two entries to make sure you understand the pattern. Notice the Python code using np.dot() to verify the result. Then, read the section 'Properties of the dot product', paying special attention to non-commutativity. This is a critical difference from regular multiplication.
A crucial property to internalize is that matrix multiplication is not commutative. In general, . Geometrically, this makes perfect sense: performing a rotation then a shear is not the same as performing a shear then a rotation. The order of transformations matters.
Conclusion
In this lesson, we demystified matrix multiplication, elevating it from a mechanical recipe to a deep conceptual tool. You now have the ability to not just compute, but also interpret, the product of matrices and vectors.
Key Takeaways:
- Matrix as Transformation: A matrix is best understood as an object that performs a linear transformation on space.
- Matrix-Vector Product: The product is the new vector that results from applying transformation to vector . It can be computed as a linear combination of 's columns or through row-column dot products.
- Matrix-Matrix Product: The product represents the composition of two transformations. It can be computed by applying to each column of .
- Non-Commutativity: The order of matrix multiplication matters (), because the order of transformations matters.
- Implementation: In Python, NumPy's
np.dot(A, B)or the@operator (A @ B) are used to perform this operation efficiently.
Preview of the Next Lesson:
Today, you learned the powerful idea that a matrix represents a transformation. In the next lesson, we will flip this around. We will start with a desired geometric transformation—like a specific rotation, scaling, or shear—and your goal will be to describe these linear transformations by constructing the specific matrices that produce them. This will complete the loop, giving you full command over the relationship between the numbers in a matrix and their geometric effect on data.