toqito.matrix_props.is_stochastic ================================= .. py:module:: toqito.matrix_props.is_stochastic .. autoapi-nested-parse:: Checks if the matrix is stochastic. Module Contents --------------- .. py:function:: 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 [@WikiStochasticMatrix]. When a matrix is right and left stochastic, it is a doubly stochastic matrix [@WikiDoublyStochasticMatrix] . !!! See Also [`is_doubly_stochastic()`][toqito.matrix_props.is_doubly_stochastic] .. rubric:: 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. ```python exec="1" source="above" import numpy as np from toqito.matrix_props import is_stochastic print(is_stochastic(np.eye(5), "right")) print(is_stochastic(np.eye(5), "left")) print(is_stochastic(np.eye(5), "doubly")) ``` ```python exec="1" source="above" from toqito.matrices import pauli from toqito.matrix_props import is_stochastic print(is_stochastic(pauli("X"), "left")) print(is_stochastic(pauli("X"), "right")) print(is_stochastic(pauli("X"), "doubly")) ``` ```python exec="1" source="above" from toqito.matrices import pauli from toqito.matrix_props import is_stochastic print(is_stochastic(pauli("Z"), "right")) print(is_stochastic(pauli("Z"), "left")) print(is_stochastic(pauli("Z"), "doubly")) ``` `mat_type` :raises TypeError: If something other than `"doubly"`, `"left"` or `"right"` is used for :param mat: Matrix of interest :param mat_type: Type of stochastic matrix. `"left"` for left stochastic matrix and `"right"` for right stochastic :param matrix and `"doubly"` for a doubly stochastic matrix.: :returns: Returns `True` if the matrix is doubly, right or left stochastic, `False` otherwise.