matrix_props.is_stochastic¶
Checks if the matrix is stochastic.
Functions¶
|
Verify matrix is doubly, right or left stochastic. |
Module Contents¶
- matrix_props.is_stochastic.is_stochastic(mat, mat_type)¶
Verify matrix is doubly, right or left stochastic.
When the nonnegative elements in a row of a square matrix sum up to 1, the matrix is right stochastic and if the columns sum up to 1, the matrix is left stochastic [1].
When a matrix is right and left stochastic, it is a doubly stochastic matrix. [2].
See also
is_doubly_stochastic
Examples
The elements of an identity matrix and a Pauli-X matrix are nonnegative such that the rows and columns sum up to 1. We expect these matrices to be left and right stochastic. The same cannot be said about a Pauli-Z or a Pauli-Y matrix.
>>> import numpy as np >>> from toqito.matrix_props import is_stochastic >>> is_stochastic(np.eye(5), "right") True >>> is_stochastic(np.eye(5), "left") True >>> is_stochastic(np.eye(5), "doubly") True
>>> from toqito.matrices import pauli >>> from toqito.matrix_props import is_stochastic >>> is_stochastic(pauli("X"), "left") True >>> is_stochastic(pauli("X"), "right") True >>> is_stochastic(pauli("X"), "doubly") True
>>> from toqito.matrices import pauli >>> from toqito.matrix_props import is_stochastic >>> is_stochastic(pauli("Z"), "right") False >>> is_stochastic(pauli("Z"), "left") False >>> is_stochastic(pauli("Z"), "doubly") False
References
[1]Wikipedia. Stochastic matrix. URL: https://en.wikipedia.org/wiki/Stochastic_matrix.
[2]Wikipedia. Doubly stochastic matrix. URL: https://en.wikipedia.org/wiki/Doubly_stochastic_matrix.
- Parameters:
mat (numpy.ndarray) – Matrix of interest
mat_type (str) – Type of stochastic matrix.
"left"
for left stochastic matrix and"right"
for right stochastic matrix and"doubly"
for a doubly stochastic matrix.
- Returns:
Returns
True
if the matrix is doubly, right or left stochastic,False
otherwise.- Raises:
TypeError – If something other than
"doubly"
,"left"
or"right"
is used format_type
- Return type:
bool