Skip to content

Instantly share code, notes, and snippets.

@sl8r000
Created November 24, 2012 05:37
Show Gist options
  • Save sl8r000/4138566 to your computer and use it in GitHub Desktop.
Save sl8r000/4138566 to your computer and use it in GitHub Desktop.
Simple Markov Matrix
$ python
>>> import numpy
>>> P = array([[1.0/3, 2.0/3], [1.0/4, 3.0/4]])
>>> P
array([[ 0.33333333, 0.66666667],
[ 0.25 , 0.75 ]])
>>> numpy.linalg.matrix_power(P, 2)
array([[ 0.27777778, 0.72222222],
[ 0.27083333, 0.72916667]])
>>> numpy.linalg.matrix_power(P, 3)
array([[ 0.27314815, 0.72685185],
[ 0.27256944, 0.72743056]])
>>> numpy.linalg.matrix_power(P, 4)
array([[ 0.27276235, 0.72723765],
[ 0.27271412, 0.72728588]])
>>> numpy.linalg.matrix_power(P, 5)
array([[ 0.2727302 , 0.7272698 ],
[ 0.27272618, 0.72727382]])
>>> numpy.linalg.matrix_power(P, 10)
array([[ 0.27272727, 0.72727273],
[ 0.27272727, 0.72727273]])
>>> numpy.linalg.matrix_power(P, 100)
array([[ 0.27272727, 0.72727273],
[ 0.27272727, 0.72727273]])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment