kuniga.me > Docs > Matrix Cheatsheet

An $m \times n$ matrix is a matrix with $m$ rows and $n$ columns. As a mnemonic, this is also the order in which we index 2-dimensional vectors in languages like Python, e.g. `m[row_index][column_index]`

. The pair $(m, n)$ defines the dimension of the matrix.

A matrix is usually denoted by uppercase letters (e.g. $M$, $A$). An element of a matrix at row $i$ and $j$ is either represented with lowercase $a_{ij}$.

An $m \times n$ matrix can be explicitly shown like:

\[A = \begin{bmatrix} a_{11} & a_{12} & \cdots & a_{1n} \\ a_{21} & a_{22} & \cdots & a_{2n} \\ \vdots & \ddots & \ddots & \vdots \\ a_{m1} & a_{m2} & \cdots & a_{mn} \\ \end{bmatrix}\]A *row vector* is a matrix with $m = 1$. A *column vector* is a matrix with $n = 1$. A *square matrix* is one where $n = m$.

The transpose of an $m \times n$ matrix $M$ , denoted as $M^T$, is a $n \times m$ matrix where $M_{ij}^T = M_{ji}$.

The determinant of a square matrix $A$, denoted by $\mid A \mid$, is a scalar that can be recursively defined as

\[\mid A \mid = \sum_{i=1}^{m} a_{ij} (-1)^{i + j} \mid M^{-}_{ij} \mid\]For any choice of column $j$. Here $A_{ij}^{-}$ is the matrix resulting from removing row $i$ and column $j$ from $A$. The base of this recursion is $m = 1$, for which $\mid A \mid = a_{11}$

The determinant $\mid A_{ij}^{-} \mid$ is also called the *minor* of $A$. In this context $(-1)^{i + j} \mid A_{ij}^{-} \mid$ is called the *cofactor* of $a_{ij}$.

The *diagonal* of a square matrix is the set of elememnts $a_{ij}$ for which $i = j$.

The *identity*, denoted by $I$, is a square matrix for which the elements in the diagonal are 1 but 0 otherwise, that is

Is only defined for matrices $A$ and $B$ with the same dimensions. $C = A + B$ is the matrix resulting from the element-wise addition of $A$ and $B$: $c_{ij} = a_{ij} + b_{ij}$.

Is only defined for matrices $A$ and $B$ with the same dimensions. $C = A - B$ is the matrix resulting from the element-wise addition of $A$ and $B$: $c_{ij} = a_{ij} - b_{ij}$.

Given matrix $A$ with dimensions $m \times k$ and $B$ with dimensions $k \times n$ (note the number of columns in $A$ must be equal to the number of rows in $B$), the product $AB$ is a $m \times n$ matrix defined as

\[AB = \begin{bmatrix} a_{11}b_{11} + a_{12}b_{21} + \cdots + a_{1k}b_{k1} & \ddots & a_{11}b_{1n} + a_{12}b_{2n} + \cdots + a_{1k}b_{kn} \\ \vdots & \ddots & \vdots \\ a_{m1}b_{11} + a_{m2}b_{21} + \cdots + a_{mk}b_{k1} & \ddots & a_{m1}b_{1n} + a_{m2}b_{2n} + \cdots + a_{mk}b_{kn} \\ \end{bmatrix}\]I find it easier to read this in Python:

See *Matrix Multiplication*.

The inverse of a square matrix $M$, denoted by $M^{-1}$ is a matrix which when pre-multiplied by $M$ is equal to the identity: $M M^{-1} = I$

See *Inverse*.

For scalars, we have the division operator $q = a/b$. This is equivalent to $qb = a$, so $q$ can be also defined as the value which multiplied by $b$ results in $a$.

Analogously for matrix, the value $Q$ for which $QB = A$ is $Q = AB^{-1}$