The Two Views of a Matrix

The next major character in our story. A grid of numbers, and so much more.

We’ve spent the last four lessons building a solid intuition for vectors. We know they are the fundamental atoms of our data, representing everything from a stock's performance to a user's taste. Now, we introduce the next major character in our story: the Matrix.

Just like with vectors, there are two primary ways to think about a matrix. One is simple and practical, the other is abstract and incredibly powerful. Mastering the ability to switch between these two views is the next giant leap in your linear algebra journey.

View #1: The Data Scientist's View (A Container for Data)

From a data scientist's or programmer's perspective, a matrix is simply a grid of numbers, arranged in rows and columns. It's a spreadsheet. It's a table in a database. You've worked with matrices your whole life, even if you haven't called them that.

A matrix A with 3 rows and 2 columns might look like this:

A=[123504]A = \begin{bmatrix} 1 & -2 \\ 3 & 5 \\ 0 & 4 \end{bmatrix}

This is the most straightforward view. A matrix is just a way of organizing data. More specifically, a matrix is a collection of vectors. You can view it as a stack of row vectors:

  • row 1 = [1, -2]
  • row 2 = [3, 5]
  • row 3 = [0, 4]

Or you can view it as a set of column vectors:

  • col 1 = [1, 3, 0]
  • col 2 = [-2, 5, 4]

This view is essential for organizing datasets. For example, if you have data on 1,000 houses, each with 15 features, your entire dataset can be represented as a single 1000 x 15 matrix. Each row is a house (a vector), and each column is a feature.

This view is practical for storing data, but it doesn't tell us what a matrix *does*. For that, we need the magic of the second view.

View #2: The Physicist's View (A Linear Transformation)

This is the most important and mind-expanding idea in all of linear algebra. A matrix is a function that transforms space. It takes in a vector and spits out a new vector. When we "multiply" a matrix by a vector, we are feeding an input vector into a transformation machine, and that machine rotates, stretches, shears, or reflects it into a new output vector.

Let's take a simple 2x2 matrix and a vector:

A=[2003],v=[12]A = \begin{bmatrix} 2 & 0 \\ 0 & 3 \end{bmatrix}, \quad v = \begin{bmatrix} 1 \\ 2 \end{bmatrix}

When we multiply A by v (a process we'll detail in a later lesson), we get a new vector:

Av=[26]A \cdot v = \begin{bmatrix} 2 \\ 6 \end{bmatrix}

What did the matrix A do? It took the input vector [1,2][1, 2] and transformed it into the output vector [2,6][2, 6]. In this case, it stretched space by a factor of 2 on the x-axis and by a factor of 3 on the y-axis. Different matrices do different things: a rotation matrix might take [1,0][1, 0] and spit out [0,1][0, 1]; a shear matrix might take a square and turn it into a slanted parallelogram.

The Core Idea for Quants & ML

Machine learning models learn the optimal transformations to solve a problem. A neural network is essentially a series of matrices. The first matrix might take a raw pixel vector and transform it to highlight edges. The next matrix transforms that to find corners. The "learning" process is just the algorithm finding the perfect numbers to put inside these matrices so that by the end, all "cat" vectors end up in one part of the space, and all "dog" vectors end up in another.

The Connection Between the Views

So how does a simple grid of numbers (View #1) contain the instructions for a complex spatial transformation (View #2)? The secret lies in the columns of the matrix.

The columns of a matrix tell you where the basis vectors land after the transformation.

Let's look at a matrix M and our standard basis vectors i=[1,0]i = [1, 0] and j=[0,1]j = [0, 1]:

M=[3112]M = \begin{bmatrix} 3 & -1 \\ 1 & 2 \end{bmatrix}
  • The first column, [3,1][3, 1], is exactly where the first basis vector, ii, ends up after being transformed by M.
  • The second column, [1,2][-1, 2], is where the second basis vector, jj, lands.

Because the transformation is "linear" (it keeps grid lines parallel and evenly spaced), knowing where the basis vectors land tells us everything we need to know about how the entire space is transformed.

Summary: Your Two New Lenses for Matrices

View #1 (Data Container)

A matrix is a grid of numbers, perfect for organizing datasets. It is a collection of row or column vectors. This is how we store information.

View #2 (Transformation)

A matrix is a function that transforms space. It takes input vectors and produces output vectors. This is how we process information.

The magic of linear algebra lies in using the numbers in the grid to understand the transformation, and using the properties of the transformation to understand the data in the grid.