ContentsChapter 1 · Linear algebra3 of 7

1.3

Matrices as transformations

In this chapter
  1. 1.1Vectors and linear combinations
  2. 1.2Span, basis and dimension
  3. 1.3Matrices as transformations
  4. 1.4Determinant, inverse and Ax = b
  5. 1.5Dot products, angles and projections
  6. 1.6Eigenvectors and eigenvalues
  7. 1.7Symmetric matrices and the SVD
Before you readA function sends ı^=(1,0)\hat\imath = (1,0) to (2,1)(2, 1) and ȷ^=(0,1)\hat\jmath = (0,1) to (1,3)(1, 3) and keeps grid lines straight and evenly spaced. Where does it send (1,2)(1, 2)
Watch: Linear transformations and matrices · 3Blue1Brown · Essence of Linear Algebra, ch. 3

A linear transformation moves every vector while keeping grid lines straight, parallel and evenly spaced, with the origin fixed. So it is decided entirely by where the basis vectors land.

A matrix records exactly that: its columns are where ı^\hat\imath and ȷ^\hat\jmath go.

A=[2113],A[xy]=x[21]+y[13]A = \begin{bmatrix} 2 & 1 \\ 1 & 3 \end{bmatrix}, \qquad A \begin{bmatrix} x \\ y \end{bmatrix} = x \begin{bmatrix} 2 \\ 1 \end{bmatrix} + y \begin{bmatrix} 1 \\ 3 \end{bmatrix}

So A(1,2)T=1⋅(2,1)+2⋅(1,3)=(4,7)A(1, 2)^T = 1\cdot(2,1) + 2\cdot(1,3) = (4, 7) Matrix times vector is a linear combination of the columns.

A = [[2, 1], [1, 3]]
The columns of A are where î and ĵ land. Drag either arrow or a slider; slide "from I to A" to watch the grid move.
Watch: Matrix multiplication as composition · 3Blue1Brown · Essence of Linear Algebra, ch. 4

Multiplying matrices means doing one transformation after another: ABAB applies BB first, then AA To get entry (i,j)(i, j) of ABAB (row ii column jj multiply row ii of AA by column jj of BB entry by entry and add: for [12]\begin{bmatrix}1 & 2\end{bmatrix} and [34]\begin{bmatrix}3 \\ 4\end{bmatrix} that is 1⋅3+2⋅4=111\cdot3 + 2\cdot4 = 11 Order matters: in general AB≠BAAB \neq BA

Shapes must match: (m×n)(n×p)(m \times n)(n \times p) gives m×pm \times p A 2×22\times2 times a 3×23\times2 is undefined.

The transpose ATA^T swaps rows and columns. A dataset is a matrix XX with one row per example, and a linear model’s parameters form a vector θ\theta Then XθX\theta is one matrix–vector product giving every example’s prediction at once.

Recall
What do the columns of a matrix tell you?
Recall
In the product ABAB which transformation happens first?
Recall
When is the product of an m×nm \times n and a p×qp \times q matrix defined, and what shape is it?
Exercise
Compute ABAB for A=[1201]A = \begin{bmatrix}1 & 2\\0 & 1\end{bmatrix} and B=[1031]B = \begin{bmatrix}1 & 0\\3 & 1\end{bmatrix} Enter the four entries row by row: top-left, top-right, bottom-left, bottom-right.