Skip to content

Instantly share code, notes, and snippets.

View ale94mleon's full-sized avatar

Alejandro Martínez-León ale94mleon

View GitHub Profile
@ale94mleon
ale94mleon / Markov_transition.py
Created February 24, 2022 11:30 — forked from tg12/Markov_transition.py
Markov transition matrix in Python
#the following code takes a list such as
#[1,1,2,6,8,5,5,7,8,8,1,1,4,5,5,0,0,0,1,1,4,4,5,1,3,3,4,5,4,1,1]
#with states labeled as successive integers starting with 0
#and returns a transition matrix, M,
#where M[i][j] is the probability of transitioning from i to j
def transition_matrix(transitions):
n = 1+ max(transitions) #number of states
M = [[0]*n for _ in range(n)]