matrix_props.is_identity

Is matrix the identity matrix.

Module Contents

Functions

is_identity(mat[, rtol, atol])

Check if matrix is the identity matrix [1].

matrix_props.is_identity.is_identity(mat, rtol=1e-05, atol=1e-08)

Check if matrix is the identity matrix [1].

For dimension \(n\), the \(n \times n\) identity matrix is defined as

\[\begin{split}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}.\end{split}\]

Examples

Consider the following matrix:

\[\begin{split}A = \begin{pmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ 0 & 0 & 1 \end{pmatrix}\end{split}\]

our function indicates that this is indeed the identity matrix of dimension 3.

>>> from toqito.matrix_props import is_identity
>>> import numpy as np
>>> mat = np.eye(3)
>>> is_identity(mat)
True

Alternatively, the following example matrix \(B\) defined as

\[\begin{split}B = \begin{pmatrix} 1 & 2 & 3 \\ 4 & 5 & 6 \\ 7 & 8 & 9 \end{pmatrix}\end{split}\]

is not an identity matrix.

>>> from toqito.matrix_props import is_identity
>>> import numpy as np
>>> mat = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]])
>>> is_identity(mat)
False

References

[1] (1,2)

Wikipedia. Identity matrix. https://en.wikipedia.org/wiki/Identity_matrix.

Parameters:
  • mat (numpy.ndarray) – Matrix to check.

  • rtol (float) – The relative tolerance parameter (default 1e-05).

  • atol (float) – The absolute tolerance parameter (default 1e-08).

Returns:

Return True if matrix is the identity matrix, and False otherwise.

Return type:

bool