Identify Matrix
An identity matrix is a matrix of $m$ by $m$ that when multiplied by a vector, does not change that vector. It is also a vector with $1$s on the diagonal and $0$ else where.
Mathematically, we represent an Identity matrix as a matrix such that:
$$ A*I = A $$ where $I$ is an identity matrix.
The identity matrix dimension are represented in their power size. For example:
$$ I^4 = \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \end{pmatrix}$$
Example:
To demonstrate that the Identity matrix, when multiplied to another matrix, A, returns A unchaged, let's multiply A below to an identity matrix:
$$ A = \begin{pmatrix} 2 & 3 & 1 \\ 1 & 1 & 5 \\ 3 & 1 & 2 \end{pmatrix}, I = \begin{pmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1 \end{pmatrix} $$
$$ A*I = \begin{pmatrix} 2*1 + 3*0 + 1*0 & 2*0 + 3*1 + 1*0 & 2*0 + 3*0 + 1*1 \\ 1*1 + 1*0 + 5*0 & 1*0 + 1*1 + 5*0 & 1*0 + 1*0 + 5*1\\ 3*1 + 1*0 + 2*0 & 3*0 + 1*1 + 2*0 & 3*0 + 1*0 + 2*1 \end{pmatrix} $$
$$ A*I = \begin{pmatrix} 2 & 3 & 1 \\ 1 & 1 & 5 \\ 3 & 1 & 2 \end{pmatrix} $$
Implementation in Numpy
Numpy has a built-it identity method that generates an identify matrix of any sizes.
import numpy as np
A = np.array([2,3,1,1,1,5,3,1,2]).reshape(3, 3)
# generate identity matrix of size 3
I = np.identity(3)
A
I
A.dot(I)