Skip to content

Instantly share code, notes, and snippets.

@manvillej
Last active November 13, 2018 19:53
Show Gist options
  • Save manvillej/b9cadb3eab076685547388554a8db7cc to your computer and use it in GitHub Desktop.
Save manvillej/b9cadb3eab076685547388554a8db7cc to your computer and use it in GitHub Desktop.
version 1 of get matrix function
>>> import numpy as np
>>> def getMatrix(matrix, turns):
... newMatrix = np.identity(matrix.shape[0])
... for i in range(turns):
... newMatrix = newMatrix*matrix
... return newMatrix
>>> twoTurnMatrix = getMatrix(transitionMatrix,2)
>>> twoTurnMatrix
matrix([
[2, 1, 0, 1, 0, 0, 0, 1, 0, 1],
[1, 2, 0, 1, 0, 0, 0, 1, 0, 0],
[0, 0, 2, 0, 1, 0, 1, 0, 0, 0],
[1, 1, 0, 2, 0, 0, 0, 0, 0, 1],
[0, 0, 1, 0, 3, 0, 1, 0, 1, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 1, 0, 1, 0, 3, 0, 1, 0],
[1, 1, 0, 0, 0, 0, 0, 2, 0, 1],
[0, 0, 0, 0, 1, 0, 1, 0, 2, 0],
[1, 0, 0, 1, 0, 0, 0, 1, 0, 2]])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment