Learn

There are a couple of important matrices that are worth discussing on their own.

Identity matrix

The identity matrix is a square matrix of elements equal to 0 except for the elements along the diagonal that are equal to 1. Any matrix multiplied by the identity matrix, either on the left or right side, will be equal to itself.

[100010001]\begin{bmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1 \\ \end{bmatrix}

Transpose matrix

The transpose of a matrix is computed by swapping the rows and columns of a matrix. The transpose operation is denoted by a superscript uppercase “T” (AT).

[abcdefghi]T=[adgbehcfi]\begin{bmatrix} a & b & c \\ d & e & f \\ g & h & i \\ \end{bmatrix} ^T = \begin{bmatrix} a & d & g \\ b & e & h \\ c & f & i \\ \end{bmatrix}

Permutation Matrix

A permutation matrix is a square matrix that allows us to flip rows and columns of a separate matrix. Similar to the identity matrix, a permutation matrix is made of elements equal to 0, except for one element in each row or column that is equal to 1. In order to flip rows in matrix A, we multiply a permutation matrix P on the left (PA). To flip columns, we multiply a permutation matrix P on the right (AP).

PA=[010001100][abcdefghi]=[defghiabc]PA = \begin{bmatrix} 0 & 1 & 0 \\ 0 & 0 & 1 \\ 1 & 0 & 0 \\ \end{bmatrix} \begin{bmatrix} a & b & c \\ d & e & f \\ g & h & i \\ \end{bmatrix} = \begin{bmatrix} d & e & f \\ g & h & i \\ a & b & c \\ \end{bmatrix}
AP=[abcdefghi][010001100]=[cabfdeigh]AP = \begin{bmatrix} a & b & c \\ d & e & f \\ g & h & i \\ \end{bmatrix} \begin{bmatrix} 0 & 1 & 0 \\ 0 & 0 & 1 \\ 1 & 0 & 0 \\ \end{bmatrix} = \begin{bmatrix} c & a & b \\ f & d & e \\ i & g & h \\ \end{bmatrix}

Instructions

Let’s walk through how permutation matrices work using the image to the right.

In the column swap, the first column becomes the second column in the resulting matrix. This is because of the location of the 1 value in the first row of the permutation matrix. Since it is located in the second column, the dot products between the rows of the first matrix and the columns of the permutation matrix cause the values of the first column to fall into the second column of the resulting matrix.

In the row swap, the first row becomes the third row of the resulting matrix. This is because of the location of the 1 value in the first column of the permutation matrix. Since it is located in the third row, the dot products between the rows of the permutation matrix and the columns of the second matrix cause the values of the first row to fall into the third row of the resulting matrix.

Can you figure out how the rest of the column swaps and row swaps occur? It might help to do out the matrix multiplication to see the patterns!

Take this course for free

By signing up for Codecademy, you agree to Codecademy's Terms of Service & Privacy Policy.
Already have an account?