Skip to content

Instantly share code, notes, and snippets.

@manvillej
Last active November 14, 2018 01:56
Show Gist options
  • Save manvillej/e01577daf617815c84027625be20b756 to your computer and use it in GitHub Desktop.
Save manvillej/e01577daf617815c84027625be20b756 to your computer and use it in GitHub Desktop.
Next State Matrix Multiplication
transitionMatrix = np.matrix([[0, 0, 0, 0, 1, 0, 1, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 1, 0, 1, 0],
[0, 0, 0, 0, 0, 0, 0, 1, 0, 1],
[0, 0, 0, 0, 1, 0, 0, 0, 1, 0],
[1, 0, 0, 1, 0, 0, 0, 0, 0, 1],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[1, 1, 0, 0, 0, 0, 0, 1, 0, 0],
[0, 0, 1, 0, 0, 0, 1, 0, 0, 0],
[0, 1, 0, 1, 0, 0, 0, 0, 0, 0],
[0, 0, 1, 0, 1, 0, 0, 0, 0, 0]], dtype=object)
"""
why am I using dtype=object? At the number of turns out we will be looking at
will be outside the range of typical data types for NumPy. Int32 & Int64 are simply too small.
With dtype=object, our numbers can be arbitarily large. It is a bit slower, but will allow us to go further out.
"""
stateVector = np.matrix([[0, 1, 0, 0, 0, 0, 0, 0, 0, 0]])
nextState = np.matmul(stateVector,transitionMatrix)
nextState # order: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
# matrix([[0, 0, 0, 0, 0, 0, 1, 0, 1, 0]])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment