Skip to content

Transposes and permutations

Flip a matrix across its diagonal, see why the product rule reverses and why AᵀA is symmetric, and reorder a signal with a permutation matrix.

Helps to know firstMatrix multiplication

Helps to know first
This topic

First, the picture

Flip a matrix across its diagonal and its rows become its columns. Watch a grid of two rows turn into a grid of two columns.

Flipping a matrix

The transpose turns every row into a column.

A = [1 2 3; 0 4 5]: 2 rows of 3 cells.

0.00 / 11.70 s
Describe this picture

The matrix A=[123045]\mathbf{A}=\begin{bmatrix}1&2&3\\0&4&5\end{bmatrix} drawn as two rows of three cells, each cell shaded by its number and labelled with it. A dashed line marks the diagonal from the top-left cell. The cells swing across that line, each passing through it like a card turned over, and the grid becomes three rows of two, labelled A⊤\mathbf{A}^\top: 1,01,0 over 2,42,4 over 3,53,5. Then the product A⊤A\mathbf{A}^\top\mathbf{A} appears beside it as a 3×33\times3 grid, gets its own dashed diagonal, and flips across it in the same way. Every cell lands on a cell with the same number, so the grid comes back unchanged, and its label reads (A⊤A)⊤=A⊤A(\mathbf{A}^\top\mathbf{A})^\top=\mathbf{A}^\top\mathbf{A}. The picture has no control.

Rows become columns

The flip in the picture at the top of the page is the transpose. The transpose of A\mathbf{A}, written A⊤\mathbf{A}^\top, has the rows of A\mathbf{A} as its columns:

A=[123045],A⊤=[102435].\mathbf{A}=\begin{bmatrix}1&2&3\\0&4&5\end{bmatrix},\qquad \mathbf{A}^\top=\begin{bmatrix}1&0\\2&4\\3&5\end{bmatrix}.

The entry in row pp and column qq of A⊤\mathbf{A}^\top is the entry in row qq and column pp of A\mathbf{A}:

(A⊤)pq=aqp.(\mathbf{A}^\top)_{pq}=a_{qp}.

So an m×nm\times n matrix has an n×mn\times m transpose. The numbers on the diagonal, where p=qp=q, stay where they are. Transpose twice and you are back where you started.

A vector is a column, so its transpose is a row. That gives a short way to write the dot product of Length and the dot product: a row times a column is one number, the sum of the matching products.

x⋅y=x⊤y.\mathbf{x}\cdot\mathbf{y}=\mathbf{x}^\top\mathbf{y}.

The product rule reverses

What is the transpose of a product? Take the matrices of Matrix multiplication, A=[1234]\mathbf{A}=\begin{bmatrix}1&2\\3&4\end{bmatrix} and B=[0110]\mathbf{B}=\begin{bmatrix}0&1\\1&0\end{bmatrix}. Their product is AB=[2143]\mathbf{A}\mathbf{B}=\begin{bmatrix}2&1\\4&3\end{bmatrix}, so

(AB)⊤=[2413]=B⊤A⊤,butA⊤B⊤=[3142].(\mathbf{A}\mathbf{B})^\top=\begin{bmatrix}2&4\\1&3\end{bmatrix}=\mathbf{B}^\top\mathbf{A}^\top, \qquad\text{but}\qquad \mathbf{A}^\top\mathbf{B}^\top=\begin{bmatrix}3&1\\4&2\end{bmatrix}.

The order reverses, as it did for inverses in The inverse matrix:

(AB)⊤=B⊤A⊤.(\mathbf{A}\mathbf{B})^\top=\mathbf{B}^\top\mathbf{A}^\top .

Here is why. Entry (p,q)(p,q) of (AB)⊤(\mathbf{A}\mathbf{B})^\top is entry (q,p)(q,p) of AB\mathbf{A}\mathbf{B}: row qq of A\mathbf{A} times column pp of B\mathbf{B}. Row qq of A\mathbf{A} is column qq of A⊤\mathbf{A}^\top, and column pp of B\mathbf{B} is row pp of B⊤\mathbf{B}^\top. So it is row pp of B⊤\mathbf{B}^\top times column qq of A⊤\mathbf{A}^\top, which is entry (p,q)(p,q) of B⊤A⊤\mathbf{B}^\top\mathbf{A}^\top. The shapes agree too: if A\mathbf{A} is 2×32\times3 and B\mathbf{B} is 3×43\times4, then AB\mathbf{A}\mathbf{B} is 2×42\times4, and both (AB)⊤(\mathbf{A}\mathbf{B})^\top and B⊤A⊤\mathbf{B}^\top\mathbf{A}^\top are 4×24\times2.

The rule has a useful form with vectors. Since (Ax)⊤=x⊤A⊤(\mathbf{A}\mathbf{x})^\top=\mathbf{x}^\top\mathbf{A}^\top,

(Ax)⋅y=x⊤A⊤y=x⋅(A⊤y).(\mathbf{A}\mathbf{x})\cdot\mathbf{y}=\mathbf{x}^\top\mathbf{A}^\top\mathbf{y}=\mathbf{x}\cdot(\mathbf{A}^\top\mathbf{y}).

A matrix can move from one side of a dot product to the other, if it is transposed on the way. Check it with A=[1234]\mathbf{A}=\begin{bmatrix}1&2\\3&4\end{bmatrix}, x=(1,0)\mathbf{x}=(1,0) and y=(0,1)\mathbf{y}=(0,1): Ax=(1,3)\mathbf{A}\mathbf{x}=(1,3) and (1,3)⋅(0,1)=3(1,3)\cdot(0,1)=3; A⊤y=(3,4)\mathbf{A}^\top\mathbf{y}=(3,4) and (1,0)⋅(3,4)=3(1,0)\cdot(3,4)=3.

Symmetric matrices

A matrix that equals its own transpose, A⊤=A\mathbf{A}^\top=\mathbf{A}, is symmetric: the numbers on each side of the diagonal mirror each other. [1225]\begin{bmatrix}1&2\\2&5\end{bmatrix} is symmetric; [1231]\begin{bmatrix}1&2\\3&1\end{bmatrix} is not.

One way to make a symmetric matrix always works. For any A\mathbf{A}, the product A⊤A\mathbf{A}^\top\mathbf{A} is symmetric, because by the product rule

(A⊤A)⊤=A⊤(A⊤)⊤=A⊤A.(\mathbf{A}^\top\mathbf{A})^\top=\mathbf{A}^\top(\mathbf{A}^\top)^\top=\mathbf{A}^\top\mathbf{A}.

That is the second flip in the picture. For the 2×32\times3 matrix at the top, the columns are (1,0)(1,0), (2,4)(2,4) and (3,5)(3,5), and entry (p,q)(p,q) of A⊤A\mathbf{A}^\top\mathbf{A} is the dot product of column pp with column qq:

A⊤A=[1232202632634].\mathbf{A}^\top\mathbf{A}=\begin{bmatrix}1&2&3\\2&20&26\\3&26&34\end{bmatrix}.

Column pp dotted with column qq is the same as column qq dotted with column pp, which is the symmetry in plain words. The other product, AA⊤=[14232341]\mathbf{A}\mathbf{A}^\top=\begin{bmatrix}14&23\\23&41\end{bmatrix}, holds the dot products of the rows, and it is symmetric too.

Permutations

A permutation matrix reorders the entries of a vector. It is the identity matrix with its rows in a new order. Here is one that moves every entry down one place, and the last entry round to the top:

P=[001100010],P[abc]=[cab].\mathbf{P}=\begin{bmatrix}0&0&1\\1&0&0\\0&1&0\end{bmatrix},\qquad \mathbf{P}\begin{bmatrix}a\\b\\c\end{bmatrix}=\begin{bmatrix}c\\a\\b\end{bmatrix}.

That is a cyclic shift. Another one reverses the order. I’ll call it J\mathbf{J}, the exchange matrix:

J=[001010100],J[abc]=[cba].\mathbf{J}=\begin{bmatrix}0&0&1\\0&1&0\\1&0&0\end{bmatrix},\qquad \mathbf{J}\begin{bmatrix}a\\b\\c\end{bmatrix}=\begin{bmatrix}c\\b\\a\end{bmatrix}.

Watch both act on a short signal of three samples.

Shift and flip

A permutation matrix reorders the entries of a vector.

x = (a, b, c), three samples, and the permutation matrix P: one 1 in every row and every column.

0.00 / 12.00 s
Describe this picture

The grid of P\mathbf{P}, with its three 1s shaded, then a column of three cells, aa, bb and cc, labelled x\mathbf{x}, and an empty column labelled Px\mathbf{P}\mathbf{x}. For each 1 in P\mathbf{P} an arrow draws from the entry it picks to the place it fills, and the entries slide along the arrows: the new column reads cc, aa, bb. Then P\mathbf{P} changes into J\mathbf{J}, with its 1s on the other diagonal, the new column empties, and the same happens again: it reads cc, bb, aa. The picture has no control.

How do you undo a permutation? Put every entry back where it came from. That is the transpose:

P⊤P=I,soP−1=P⊤.\mathbf{P}^\top\mathbf{P}=\mathbf{I},\qquad\text{so}\qquad \mathbf{P}^{-1}=\mathbf{P}^\top.

The reason is short. The columns of P\mathbf{P} are the unit vectors e1,e2,e3\mathbf{e}_1,\mathbf{e}_2,\mathbf{e}_3 in some order. Entry (p,q)(p,q) of P⊤P\mathbf{P}^\top\mathbf{P} is column pp dotted with column qq: 1 when they are the same unit vector and 0 when they are not. For the cyclic shift, P⊤\mathbf{P}^\top shifts the other way: (a,b,c)(a,b,c) goes to (b,c,a)(b,c,a). The flip undoes itself: J2=I\mathbf{J}^2=\mathbf{I}, and J⊤=J\mathbf{J}^\top=\mathbf{J}.

There are 3⋅2⋅1=63\cdot2\cdot1=6 permutation matrices of size 3×33\times3, one for each order of three things.

Be careful not to stretch the rule. For a permutation the transpose is the inverse, but for most matrices it is not. The matrix [2−111]\begin{bmatrix}2&-1\\1&1\end{bmatrix} has transpose [21−11]\begin{bmatrix}2&1\\-1&1\end{bmatrix} and inverse 13[11−12]\tfrac13\begin{bmatrix}1&1\\-1&2\end{bmatrix}, two different matrices.

Worked example

  1. A shape. The transpose of a 2×32\times3 matrix is 3×23\times2.
  2. Two products. For A=[123045]\mathbf{A}=\begin{bmatrix}1&2&3\\0&4&5\end{bmatrix}: A⊤A=[1232202632634]\mathbf{A}^\top\mathbf{A}=\begin{bmatrix}1&2&3\\2&20&26\\3&26&34\end{bmatrix} and AA⊤=[14232341]\mathbf{A}\mathbf{A}^\top=\begin{bmatrix}14&23\\23&41\end{bmatrix}, both symmetric.
  3. The product rule. For A=[1234]\mathbf{A}=\begin{bmatrix}1&2\\3&4\end{bmatrix} and B=[0110]\mathbf{B}=\begin{bmatrix}0&1\\1&0\end{bmatrix}, (AB)⊤=B⊤A⊤=[2413](\mathbf{A}\mathbf{B})^\top=\mathbf{B}^\top\mathbf{A}^\top=\begin{bmatrix}2&4\\1&3\end{bmatrix}.
  4. Shapes of a product. A\mathbf{A} is 2×32\times3 and B\mathbf{B} is 3×43\times4: (AB)⊤(\mathbf{A}\mathbf{B})^\top is 4×24\times2.
  5. A cyclic shift. P\mathbf{P} sends (1,2,3)(1,2,3) to (3,1,2)(3,1,2), and P⊤\mathbf{P}^\top sends it back.
  6. A flip. J\mathbf{J} sends (1,2,3)(1,2,3) to (3,2,1)(3,2,1), and J\mathbf{J} again sends it back.
  7. Predict. Is A⊤A\mathbf{A}^\top\mathbf{A} symmetric for every A\mathbf{A}, even one that is not square? Yes: its transpose is itself.

Where you’ll meet this

The product A⊤A\mathbf{A}^\top\mathbf{A} is at the heart of fitting a line or curve to data, on the page Least squares. The same product, built from data with the averages removed, and divided by a count, gives the covariance matrices of statistics.

The FFT reorders its input with a permutation called bit reversal. For 8 samples it takes them in the order 0, 4, 2, 6, 1, 5, 3, 7. A ring buffer, the circular store that real-time audio programs use for the latest samples, is a cyclic shift in action.

In signal processing · shift and flip matrices

A signal of NN samples is a vector, and shifting or reversing it is a permutation matrix. The page Shifting, reversing and scaling time moves signals this way, and Properties of the DFT uses the circular shift, which is the cyclic P\mathbf{P} above. One difference in counting: matrix and vector entries count from 1, while samples x[n]x[n] count from 0. So the vector’s entry xqx_q is the sample x[q−1]x[q-1], and (a,b,c)(a,b,c) here is x[0]x[0], x[1]x[1], x[2]x[2].

Reference card

QuantityFormulaNotes
Transpose(A⊤)pq=aqp(\mathbf{A}^\top)_{pq}=a_{qp}rows become columns; m×nm\times n becomes n×mn\times m
Dot productx⋅y=x⊤y\mathbf{x}\cdot\mathbf{y}=\mathbf{x}^\top\mathbf{y}a row times a column
Product(AB)⊤=B⊤A⊤(\mathbf{A}\mathbf{B})^\top=\mathbf{B}^\top\mathbf{A}^\topreverse order
Moving a matrix(Ax)⋅y=x⋅(A⊤y)(\mathbf{A}\mathbf{x})\cdot\mathbf{y}=\mathbf{x}\cdot(\mathbf{A}^\top\mathbf{y})transpose on the way
SymmetricA⊤=A\mathbf{A}^\top=\mathbf{A}A⊤A\mathbf{A}^\top\mathbf{A} always is
Permutationthe identity with its rows reorderedP−1=P⊤\mathbf{P}^{-1}=\mathbf{P}^\top
Cyclic shift(a,b,c)→(c,a,b)(a,b,c)\to(c,a,b)undone by P⊤\mathbf{P}^\top
FlipJ\mathbf{J}: (a,b,c)→(c,b,a)(a,b,c)\to(c,b,a)J2=I\mathbf{J}^2=\mathbf{I}

Keep reading with a free account.

By creating an account you accept the terms of use.

Sign in

Already have an account? Use the service you signed up with.

Or keep reading: get new lessons by email

Are you 13 or over?

Accounts and email updates are for people aged 13 or over. We keep only your answer, never your date of birth.

End of the lesson

Where to go next.

Phasorium

Account

Sign inKeep your place on any device

Subjects

Site

Look