is_identity
¶
Checks if the matrix is an identity matrix.
is_identity
¶
Check if matrix is the identity matrix 1.
For dimension \(n\), the \(n \times n\) identity matrix is defined as
\[
I_n =
\begin{pmatrix}
1 & 0 & 0 & \ldots & 0 \\
0 & 1 & 0 & \ldots & 0 \\
0 & 0 & 1 & \ldots & 0 \\
\vdots & \vdots & \vdots & \ddots & \vdots \\
0 & 0 & 0 & \ldots & 1
\end{pmatrix}.
\]
Examples:
Consider the following matrix:
\[
A = \begin{pmatrix}
1 & 0 & 0 \\
0 & 1 & 0 \\
0 & 0 & 1
\end{pmatrix}
\]
our function indicates that this is indeed the identity matrix of dimension 3.
import numpy as np
from toqito.matrix_props import is_identity
mat = np.eye(3)
print(is_identity(mat))
True
Alternatively, the following example matrix \(B\) defined as
\[
B = \begin{pmatrix}
1 & 2 & 3 \\
4 & 5 & 6 \\
7 & 8 & 9
\end{pmatrix}
\]
is not an identity matrix.
import numpy as np
from toqito.matrix_props import is_identity
mat = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
print(is_identity(mat))
False
Parameters:
-
mat(ndarray) –Matrix to check.
-
rtol(float, default:1e-05) –The relative tolerance parameter (default 1e-05).
-
atol(float, default:1e-08) –The absolute tolerance parameter (default 1e-08).
Returns:
-
bool–Return
Trueif matrix is the identity matrix, andFalseotherwise.
References
1 Wikipedia. Identity matrix. link.