toqito icon indicating copy to clipboard operation
toqito copied to clipboard

Feature: Check if matrix stochastic

Open vprusso opened this issue 1 year ago • 0 comments

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.

vprusso avatar Apr 20 '24 16:04 vprusso