I'm trying to simulate data given a transition matrix. I made the transition matrix using this answered question, so let's say my data is:
days=['rain', 'rain', 'rain', 'clouds', 'rain', 'sun', 'clouds', 'clouds',
'rain', 'sun', 'rain', 'rain', 'clouds', 'clouds', 'sun', 'sun',
'clouds', 'clouds', 'rain', 'clouds', 'sun', 'rain', 'rain', 'sun',
'sun', 'clouds', 'clouds', 'rain', 'rain', 'sun', 'sun', 'rain',
'rain', 'sun', 'clouds', 'clouds', 'sun', 'sun', 'clouds', 'rain',
'rain', 'rain', 'rain', 'sun', 'sun', 'sun', 'sun', 'clouds', 'sun',
'clouds', 'clouds', 'sun', 'clouds', 'rain', 'sun', 'sun', 'sun',
'clouds', 'sun', 'rain', 'sun', 'sun', 'sun', 'sun', 'clouds',
'rain', 'clouds', 'clouds', 'sun', 'sun', 'sun', 'sun', 'sun', 'sun',
'clouds', 'clouds', 'clouds', 'clouds', 'clouds', 'sun', 'rain',
'rain', 'rain', 'clouds', 'sun', 'clouds', 'clouds', 'clouds', 'rain',
'clouds', 'rain', 'sun', 'sun', 'clouds', 'sun', 'sun', 'sun', 'sun',
'sun', 'sun', 'rain']
I create the transition matrix using:
pd.crosstab(pd.Series(days[1:],name='Tomorrow'),
pd.Series(days[:-1],name='Today'),normalize=1)
Which has the output:
Today clouds rain sun
Tomorrow
clouds 0.40625 0.230769 0.309524
rain 0.28125 0.423077 0.142857
sun 0.31250 0.346154 0.547619
Now, I want to generate output using the matrix above. So let's say my random starting point would be 'rain', then, the output would be (for example):
[rain, rain, clouds, sun]
Unfortunately, I can only find solutions where the matrix is made using dictionaries.
Edit: I used:
pd.crosstab(pd.Series(word[:-1],name='Current'),
pd.Series(word[1:],name='Next'),normalize=0)
My own matrix:
Next a b c d e f g h
Current
a 0.0 0.0 0.428571 0.571429 0.0 0.0 0.0 0.0
b 0.0 0.0 0.230769 0.769231 0.0 0.0 0.0 0.0
c 0.0 0.0 0.000000 0.000000 0.0 0.0 1.0 0.0
d 0.0 0.0 0.000000 0.000000 0.0 0.0 0.0 1.0
e 1.0 0.0 0.000000 0.000000 0.0 0.0 0.0 0.0
f 0.0 1.0 0.000000 0.000000 0.0 0.0 0.0 0.0
g 0.0 0.0 0.000000 0.000000 1.0 0.0 0.0 0.0
h 0.0 0.0 0.000000 0.000000 0.0 1.0 0.0 0.0