Hello! Welcome back to our exploration of the mathematical foundations for computer vision.
In the last lesson, we established a crucial link between the determinant of a matrix and its ability to be inverted. You learned that the determinant represents the factor by which a matrix scales the area (or volume) of the space it transforms. A non-zero determinant means the transformation is reversible, while a zero determinant implies the transformation collapses space into a lower dimension.
Today, we will dive deeper into this idea of a "matrix as a transformation." This lesson is dedicated to fulfilling the learning outcome: to explain the geometric interpretation of a matrix as a linear transformation. We will move beyond if or by how much a matrix transforms space, and focus on what these transformations actually look like. You will learn to visualize matrix multiplication as a concrete geometric operation, such as a rotation, reflection, scaling, or shear.
1. From Matrix Multiplication to Linear Transformations
At its heart, the operation of multiplying a matrix by a vector to get a new vector is a function that maps an input vector to an output vector. This mapping is called a transformation.

Matrices don't just perform any random transformation; they perform a special kind called a linear transformation. For a transformation to be linear, it must satisfy two properties for any vectors , and any scalar :
- Additivity:
- Homogeneity:
Geometrically, these properties mean that the transformation keeps grid lines parallel and evenly spaced, and the origin remains fixed. The reading below formalizes this definition.
Introduction to Linear Algebra for Applied Machine ...
The following text, 'Introduction to Linear Algebra for Applied Machine...', introduces the formal definition of a linear mapping (transformation) and its essential properties.
Please read the section 'Linear mappings'. Focus on the two rules that define a linear mapping and the 'superposition property'. Pay close attention to the final paragraph which states that in linear algebra, these transformations are performed by matrix multiplication.
2. The Key Insight: Transformations are Defined by Basis Vectors
Understanding the two properties is good, but there is a more intuitive and powerful way to think about linear transformations.
Consider any vector in a 2D plane, for instance . This vector can be expressed as a linear combination of the standard basis vectors, and :
Now, let's apply a linear transformation to . Because of the properties of linearity, we can write:
This is a profound result. It means that if we know where the basis vectors and land after the transformation (i.e., we know and ), we can determine where any vector in the entire space lands.
The transformation is completely described by what it does to the basis vectors. So, where do we find these transformed basis vectors?
The columns of a transformation matrix are the transformed basis vectors.
Let a 2x2 matrix be .
- The first column, , is the vector — where the first basis vector lands.
- The second column, , is the vector — where the second basis vector lands.
This gives you the power to look at any 2x2 matrix and immediately know how it transforms 2D space.
Test your understanding!
Consider a transformation that rotates the entire 2D plane 90 degrees counter-clockwise. What matrix represents this transformation? Think about where the basis vectors and end up.
Show answer
-
The first basis vector, , lies on the x-axis. Rotating it 90 degrees counter-clockwise makes it point along the y-axis, so it becomes . This is the first column of our matrix.
-
The second basis vector, , lies on the y-axis. Rotating it 90 degrees counter-clockwise makes it point along the negative x-axis, so it becomes . This is the second column of our matrix.
Combining these, the rotation matrix is:
3. A Catalogue of Common Transformations
With this core intuition, let's explore the matrix representations for several common geometric operations. The following reading provides a great overview, including the matrix forms and NumPy code. As you go through it, try to apply the "transformed basis vectors" logic to each matrix to see why it works.
Introduction to Linear Algebra for Applied Machine ...
The resource 'Introduction to Linear Algebra for Applied Machine ...' details several key transformations. This will solidify your understanding by providing concrete examples.
Please read the section 'Special linear mappings'. For each transformation (Scaling, Reflection, Shear, Rotation), examine the matrix form provided. Try to deduce for yourself how the basis vectors are being transformed to produce that matrix. You can skim the Python code used for plotting, but do observe the matrix definitions themselves.
Let's summarize the key transformations you just read about:
- Scaling: Stretches or shrinks space. A scaling matrix is a diagonal matrix, like . The first column shows being scaled by , and the second shows being scaled by .
- Shear: Slants the space. A horizontal shear matrix like leaves unchanged but transforms into , effectively "pushing" the top of the grid.
- Rotation: Rotates space around the origin. We derived the 90-degree rotation matrix earlier. The general form is .
- Reflection: Flips space across a line. For example, reflection across the y-axis is represented by , which reverses but leaves alone.
4. Constructing Your Own Transformation Matrices
Now, let's put your new knowledge into practice. The following exercises ask you to construct a matrix to achieve a specific transformation. This is a powerful way to test your understanding.
The resource below is part of a course from Neuromatch Academy. The course heavily uses videos, which I know you prefer to avoid. However, its text-based explanations and coding exercises are excellent. We will use only the coding exercise from this resource.
The 'Tutorial 2: Matrices' from Neuromatch Academy includes an excellent coding exercise that challenges you to build transformation matrices from scratch. This is a perfect way to apply the concept of transforming basis vectors.
Please navigate to 'Coding Exercise 1.2: Creating matrices for transformations'. Ignore the surrounding video links. Read the instructions for the two challenges: creating a matrix for reflection and one for projection. Try to solve them by thinking about where the basis vectors should land first, then filling in the matrix A in the code cell.
These exercises should highlight the connection between a geometric goal (e.g., "project onto the x-axis") and the algebraic representation (the matrix). The projection matrix, , is particularly interesting. It takes the 2D plane and collapses it onto the x-axis. What does this remind you of from our last lesson? Its determinant is . This is a singular matrix, which perfectly matches our prior understanding: it collapses space, so it's not invertible.
The set of all possible outputs of a transformation is its range, and the dimension of that range is its rank. For the projection matrix, the range is the x-axis, which is a 1-dimensional space, so its rank is 1.
Conclusion
Today you've unlocked a new way to see matrices. They are not just tables of numbers for rote calculation; they are dynamic operators that stretch, squeeze, rotate, and shear vector spaces. This geometric viewpoint is invaluable in machine learning, where complex models like neural networks are essentially long chains of linear and non-linear transformations designed to reshape data into a more useful form.
Here are the main takeaways:
- Matrix-vector multiplication, , is a linear transformation that maps a vector to a new vector.
- Linear transformations keep the origin fixed and grid lines straight, parallel, and evenly spaced.
- The key insight: the columns of a matrix tell you where the basis vectors land after the transformation. This allows you to construct and interpret any linear transformation.
- Common geometric operations like scaling, shear, rotation, and reflection can all be represented by specific 2x2 matrices.
Preview of the Next Lesson:
In this lesson, we saw how matrices can transform vectors, changing their direction and magnitude. But what if a matrix transforms a vector without changing its direction, only its length? These special vectors, which are only scaled by the transformation, are called eigenvectors, and their corresponding scaling factors are eigenvalues. In the next lesson, we will define eigenvalues and eigenvectors and explore their profound geometric significance. They are foundational to dimensionality reduction techniques like Principal Component Analysis (PCA), which is widely used in computer vision.