0PricingLogin
Pandas & NumPy Academy · Lesson

Determinants, Inverses, and Transposes

Compute matrix determinants with np.linalg.det, inverses with np.linalg.inv, and transposes with .T.

The Transpose of a Matrix

The transpose of a matrix flips it over its diagonal: rows become columns and columns become rows. If A has shape (m, n), then A.T has shape (n, m). Transposes appear everywhere in linear algebra: computing covariance matrices, implementing gradient backpropagation, and converting between row-vector and column-vector conventions. NumPy accesses the transpose with the .T attribute — no copy is made, it is just a view with reordered strides.

import numpy as np

A = np.array([[1, 2, 3],
              [4, 5, 6]])
print('A shape:', A.shape)       # (2, 3)
print('A.T shape:', A.T.shape)   # (3, 2)
print(A.T)

Transpose in Practice

A frequent pattern is computing A.T @ A, which produces a symmetric square matrix that appears in least squares regression, PCA, and normal equations. If A has shape (n, p), then A.T @ A has shape (p, p). The result is always symmetric because (A.T @ A)[i,j] == (A.T @ A)[j,i]. This property is exploited by many numerical solvers for efficiency.

import numpy as np

A = np.array([[1.0, 2.0],
              [3.0, 4.0],
              [5.0, 6.0]])  # shape (3, 2)

ATA = A.T @ A   # shape (2, 2), symmetric
print('A.T @ A:')
print(ATA)
print('Is symmetric:', np.allclose(ATA, ATA.T))

All lessons in this course

  1. Matrix Multiplication with np.matmul and @
  2. Determinants, Inverses, and Transposes
  3. Solving Linear Systems
  4. Eigenvalues and SVD Overview
← Back to Pandas & NumPy Academy