The transpose of a matrix A, written A⊤, turns its rows into columns: row i of A becomes column i of A⊤. So the entry in row i, column j of A⊤ is aji, and an m×n matrix has an n×m transpose.
M=(132−104)M⊤=1203−14
Transposing twice gives back the matrix you started with: (A⊤)⊤=A. A column vector turned on its side is a row: for u=(3,1), u⊤=(31), a 1×2 matrix.
The transpose of a product
With A and C from lesson 3.2.1, AC=(4513), so (AC)⊤=(4153). That equals C⊤A⊤, with the order reversed. The other order, A⊤C⊤=(2135), does not match.
Here is why. Entry (1,2) of (AC)⊤ is entry (2,1) of AC: row 2 of A dotted with column 1 of C, (−1,3)⋅(1,2)=5.
Those two vectors are column 2 of A⊤ and row 1 of C⊤. So the same dot product is entry (1,2) of C⊤A⊤.
Shapes say the same. M is 2×3 and N=120013 is 3×2, so MN and its transpose are 2×2. N⊤M⊤ is (2×3)(3×2), also 2×2; but M⊤N⊤ is (3×2)(2×3), a 3×3 matrix.
Rule: Transpose
(A⊤)ij=aji(AB)⊤=B⊤A⊤
The transpose swaps rows and columns. The transpose of a product is the product of the transposes in the reverse order.
Try it
.T is the transpose in NumPy. The first lines print M⊤ and both shapes.
Then (AC)⊤ and C⊤A⊤ agree, while A⊤C⊤ does not.
⌘/Ctrl + Enter runs the cell
Symmetric matrices
A square matrix is symmetric when it equals its transpose, A⊤=A: every entry aij equals aji. The matrix is a mirror image of itself across its main diagonal, the entries a11,a22,… from top left to bottom right.
S=(2112)K=4−10−132025
Both are symmetric. A=(2−113) is not: a12=1 but a21=−1.
Two ways always make a symmetric matrix. M⊤M is symmetric for any M, because (M⊤M)⊤=M⊤(M⊤)⊤=M⊤M by the rule above. And A+A⊤ is symmetric for any square A.
Case study 3.2.5 meets the most important symmetric matrix in finance, the covariance matrix.
Try it
np.array_equal(S, S.T) tests for symmetry: true for S, false for A.
M⊤M is 3×3 and MM⊤ is 2×2; each mirrors itself across its diagonal. So does A+A⊤.
⌘/Ctrl + Enter runs the cell
The dot product as uᵀv
Lesson 3.2.1 found that a row times a column is a single number, their dot product. A column vector u with n components is n×1, so u⊤ is 1×n and u⊤v is 1×1.
Rule: The dot product as a matrix product
u⊤v=u⋅vu⊤u=∥u∥2
u⊤v=u1v1+⋯+unvn, the dot product of lesson 3.1.2. From here on both notations are used.
For u=(3,1) and v=(1,2), u⊤v=3+2=5, and u⊤u=10, so the length is ∥u∥=10≈3.162278. The other order, uv⊤, is (2×1)(1×2): the 2×2 table (3162), not a number.
A row, a square matrix and a column multiply to a number too: u⊤Sv is (1×2)(2×2)(2×1). Here Sv=(4,5), so u⊤Sv=12+5=17. Case study 3.2.5 writes a portfolio's variance in exactly this form.
Try it
Here u and v are 2-D columns, so that .T makes a row. u.T @ v prints as a 1×1 array.
1-D arrays have no row or column shape. For them a @ b is the dot product directly, and a @ S @ b the number u⊤Sv.
⌘/Ctrl + Enter runs the cell
The identity matrix
The identity matrixI is square, with 1 at every place on the main diagonal and 0 everywhere else. I2 and I3 are its 2×2 and 3×3 versions:
I2=(1001)I3=100010001
As a map it changes nothing: its columns are e1 and e2 themselves, so every vector stays put (lesson 3.2.2). It plays the part that 1 plays for numbers.
Rule: The identity
Ix=xAI=IA=A
Multiplying by I on either side leaves a matrix unchanged. For a matrix that is not square, use the identity of the size that fits on each side.
Try it
np.eye(n) builds In. Its entries print as decimals, 1. and 0..
⌘/Ctrl + Enter runs the cell
The inverse
In lesson 3.2.1, A=(2−113) sent x=(2,1) to (5,1). Run backwards: which x does A send to (5,1)? The map that answers it for every point is the inverse of A, written A−1.
Rule: The inverse
AA−1=A−1A=I
A−1 undoes A, and A undoes A−1. Only a square matrix can have an inverse, and not every square matrix has one. The −1 is a label, as for an inverse function (lesson 1.1.3): A−1 is not 1 divided by each entry.
A map with an inverse, and one without. A moves the unit square to a parallelogram and A−1 brings every point back. Z squashes the square onto a segment of one line; three different points land on (2,1), so no map can send it back to just one.
The 2 × 2 formula
For a 2×2 matrix the inverse has a formula. Swap the two diagonal entries, change the sign of the other two, and divide by the number ad−bc.
Rule: Inverse of a 2 × 2 matrix
A=(acbd)A−1=ad−bc1(d−c−ba)
The inverse exists exactly when ad−bc=0. Multiplying out shows why the formula works: A(d−c−ba) is (ad−bc)I.
Three examples:
B=(2111) has ad−bc=2−1=1, so B−1=(1−1−12).
G=(4123) has ad−bc=12−2=10, so G−1=101(3−1−24)=(0.3−0.1−0.20.4).
A has ad−bc=6−(−1)=7, so A−1=71(31−12). It sends (5,1) to 71(14,7)=(2,1), the point we started from.
Check B entry by entry. Row 1 of B dotted with column 1 of B−1 is 2⋅1+1⋅(−1)=1, and with column 2 it is 2⋅(−1)+1⋅2=0. Row 2 gives 1−1=0 and −1+2=1: together, the identity.
Try it
inverse_2x2 is the formula. For each example the cell prints the inverse, rounded to 4 places, and checks AA−1=I and A−1A=I.
The last line undoes A: A−1(5,1)=(2,1).
⌘/Ctrl + Enter runs the cell
Undoing the maps of lesson 3.2.2
Each map in the gallery of lesson 3.2.2 has a natural undo, and the formula agrees with it.
Shear(1011): shear back, (10−11).
Stretch(2000.5): shrink back, (0.5002).
Quarter turn(01−10): turn back, (0−110). That is also its transpose: for every rotation, R−1=R⊤.
Reflection(100−1): reflect again. It is its own inverse.
Projection(1000): no undo. Its ad−bc is 1⋅0−0⋅0=0.
Undoing two maps
To undo "shear, then turn", undo the turn first and the shear second: the last step is the first one undone. With the shear H=(1011) and the quarter turn R=(01−10), RH means shear first, so its inverse is H−1R−1.
Rule: Inverse of a product
(AB)−1=B−1A−1
The order reverses, as for the transpose. Both A and B must have inverses.
Follow (3,2). The shear sends it to (5,2) and the turn to (−2,5).
Applying H−1R−1 brings (−2,5) back to (3,2). The wrong order, R−1H−1, sends it to (5,7) instead.
Try it
The first line prints (3,2) after the shear, then y, the point after the shear and the turn. Undoing in the right order gives (3,2) back; the wrong order does not.
np.linalg.inv(R @ H) matches H−1R−1. Adding 0.0 turns a -0. into 0.. The last line confirms R−1=R⊤.
⌘/Ctrl + Enter runs the cell
When there is no inverse
A 2×2 matrix with ad−bc=0 has no inverse. Take
Z=(10.521)
with ad−bc=1−1=0. Its second column, (2,1), is twice its first, (1,0.5). So every image Zx=x1(1,0.5)+x2(2,1) is a multiple of (1,0.5): the whole plane is flattened onto the line x2=x1/2.
A flattened plane cannot be unflattened. The points (2,0), (0,1), (1,0.5) and (4,−1) all land on (2,1), so no map can send (2,1) back to a single start. The vector (2,−1) even lands on (0,0), alongside 0 itself.
A matrix with no inverse is called singular. Lesson 3.4.1 calls ad−bc the determinant and reads it as the factor by which the map scales areas, so 0 means flattened. Lesson 3.3.2 finds the same failure in larger matrices.
Try it
The four points on the line x1+2x2=2 all land on (2,1), and (2,−1) lands on (0,0).
np.linalg.inv refuses Z with a LinAlgError. Not every singular matrix is caught this way: rounding can hide one, as lesson 3.3.2 shows.
⌘/Ctrl + Enter runs the cell
Solving Ax = b in NumPy
To find x with Ax=b, multiply both sides by A−1: x=A−1b. That is the right idea, but not the right code.
np.linalg.solve(A, b) finds x without building A−1. It does less arithmetic, and so it usually makes smaller rounding errors, which matters for large or nearly singular systems. Lesson 3.3.1 shows the method it uses, elimination.
Rule: Solving Ax = b
x=A−1bcomputed by np.linalg.solve
Use np.linalg.inv when you need the inverse matrix itself. To solve a system, use np.linalg.solve.
For A and b=(5,1), both give (2,1). For the 3×3 system Lx=c,
210131014x=359
solve gives x≈(1.2222,0.5556,2.1111), and multiplying back by L gives c. An exactly singular matrix such as Z makes solve raise the same LinAlgError as inv.
Try it
The inverse of A to 4 places, then A−1b and solve side by side.
np.allclose checks that Lx=c and that the two methods agree. The last lines try Z.
⌘/Ctrl + Enter runs the cell
Common mistakes
The order reverses.(AB)⊤=B⊤A⊤ and (AB)−1=B−1A−1.
A−1 is not the reciprocal of each entry. For B=(2111) the reciprocals give (0.5111), but B−1=(1−1−12).
In the 2×2 formula, swap a and d and change the signs of b and c; do not swap b and c. Then divide by ad−bc.
Check ad−bc first. If it is 0, there is no inverse: the map flattens the plane.
u⊤v is a number; uv⊤ is a matrix.
Only square matrices have inverses, and in code, solve systems with np.linalg.solve rather than inv.
Transpose, identity and inverse
0 of 12 correct
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
How to type answers
Powers with ^: x^7, 2^(1/3), a^-2.
Multiply with * or by writing side by side: 3x^2, 2(x+1).
ln(x) is the natural log, log(x, 2) is log base 2, e is Euler's number, sqrt(x) is a square root.
sin(x), cos(x) and tan(x) take radians; write pi for π and sin(x)^2 for sin²x.
Your first answer to each question is saved: it counts towards your score and brings the question back for review.
Exact answers like ln(20)/ln(3) are best. Decimals need about 4 significant figures.
Summary card
A⊤ swaps rows and columns, (A⊤)ij=aji; (AB)⊤=B⊤A⊤.
A is symmetric when A⊤=A. M⊤M and A+A⊤ are always symmetric.
u⊤v=u⋅v and u⊤u=∥u∥2; uv⊤ is a matrix.
I has 1 on the diagonal and 0 elsewhere: Ix=x and AI=IA=A.
AA−1=A−1A=I. For 2×2: A−1=ad−bc1(d−c−ba), which exists exactly when ad−bc=0. (AB)−1=B−1A−1.
ad−bc=0 means the map flattens the plane and cannot be undone: the matrix is singular.
Solve Ax=b with np.linalg.solve, not by computing np.linalg.inv.