toqito.matrix_props.is_projection
- toqito.matrix_props.is_projection(mat, rtol=1e-05, atol=1e-08)[source]
Check if matrix is a projection matrix [WikProj].
A matrix is a projection matrix if it is positive semidefinite (PSD) and if
\[\begin{equation} X^2 = X \end{equation}\]where \(X\) is the matrix in question.
Examples
Consider the following matrix
\[\begin{split}A = \begin{pmatrix} 0 & 1 \\ 0 & 1 \end{pmatrix}\end{split}\]our function indicates that this is indeed a projection matrix.
>>> from toqito.matrix_props import is_projection >>> import numpy as np >>> A = np.array([[0, 1], [0, 1]]) >>> is_projection(A) True
Alternatively, the following example matrix \(B\) defined as
\[\begin{split}B = \begin{pmatrix} -1 & -1 \\ -1 & -1 \end{pmatrix}\end{split}\]is not positive definite.
>>> from toqito.matrix_props import is_projection >>> import numpy as np >>> B = np.array([[-1, -1], [-1, -1]]) >>> is_projection(B) False
References
[WikProj]Wikipedia: Projection matrix. https://en.wikipedia.org/wiki/Projection_matrix
- Parameters:
mat – Matrix to check.
rtol – The relative tolerance parameter (default 1e-05).
atol – The absolute tolerance parameter (default 1e-08).
- Returns:
Return
Trueif matrix is a projection matrix, andFalseotherwise.