Same Object, Different Structure
A matrix's shape and constraints determine its properties. A constraint is not merely a restriction; it is a type hint for which operations exist and which can be cheap.
| Type | Constraint | Why it is useful |
|---|---|---|
| Square | same number of rows and columns | determinants and eigenvalues are defined, and a nonsingular square matrix has an inverse |
| Rectangular | changes dimensionality, such as projecting 1,024 dimensions to 256 | |
| Diagonal | zero off the diagonal | scales each axis and needs only diagonal entries for many operations |
| Identity | ones on the diagonal, zero elsewhere | multiplicative identity: |
| Zero | all entries are zero | additive identity for matrices of the same shape |
| Symmetric | common in covariance and energy models, with useful real eigendecomposition properties | |
| Sparse | most entries are zero | stores and computes mainly nonzero entries to save memory and work |
Why You Should Care
Identity matrices appear in regularization and linear-system formulas, diagonal matrices in scaling and SVD, and symmetric matrices in covariance, graph, and energy problems. Sparse storage is what lets enormous recommendation matrices and graphs fit in memory.
A rectangular matrix has no ordinary two-sided inverse, though least-squares solutions and pseudoinverses may apply. A square matrix can also be singular and noninvertible. Shape alone never guarantees an inverse.
import numpy as np
D = np.diag([2., 0.5, -1.]) v = np.array([10., 10., 10.])
print('D =') print(D) print('D @ v =', D @ v)