toqito
toqito copied to clipboard
Feature: Check if matrix stochastic
Provide a function that takes in as input a matrix (as a numpy array) and returns True if the matrix is stochastic and False otherwise.
A function like the following could be written:
import numpy as np
def is_stochastic(mat: np.ndarray) -> bool:
"""Check if matrix is stochastic.
A matrix is stochastic if the rows all sum to 1.
"""
return np.allclose([sum(e) for e in mat], 1)
One would also need to provide proper documentation, examples, and unit tests for this function.