matrix_props.is_permutation

Is matrix a permutation matrix.

Module Contents

Functions

is_permutation(mat)

Determine if a matrix is a permutation matrix [1].

matrix_props.is_permutation.is_permutation(mat)

Determine if a matrix is a permutation matrix [1].

A matrix is a permutation matrix if each row and column has a single element of 1 and all others are 0.

Examples

Consider the following permutation matrix

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

which is indeed a permutation matrix.

>>> from toqito.matrix_props import is_permutation
>>> import numpy as np
>>> A = np.array([[1, 0, 0], [0, 0, 1], [0, 1, 0]])
>>> is_permutation(A)
True

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

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

has 2 columns with all zero values and is thus not a permutation matrix.

>>> from toqito.matrix_props import is_permutation
>>> import numpy as np
>>> B = np.array([[1, 0, 0], [1, 0, 0], [1, 0, 0]])
>>> is_permutation(B)
False

References

[1] (1,2)

Wikipedia. Permutation matrix. https://en.wikipedia.org/wiki/Permutation_matrix.

Parameters:

mat (numpy.ndarray) – The matrix to check.

Returns:

Returns True if the matrix is a permutation matrix and False otherwise.

Return type:

bool