Im trying to build a 3x3 transition matrix with this data
days=[\'rain\', \'rain\', \'rain\', \'clouds\', \'rain\', \'sun\', \'clouds\', \'clouds\',
\'rai
It seems you want to create a matrix of the probability of rain coming after sun or clouds coming after sun (or etc). You can spit out the probability matrix (not a math term) like so:
def probabilityMatrix():
tomorrowsProbability=np.zeros((3,3))
occurancesOfEach = Counter(data)
myMatrix = Counter(zip(data, data[1:]))
probabilityMatrix = {key : myMatrix[key] / occurancesOfEach[key[0]] for key in myMatrix}
return probabilityMatrix
print(probabilityMatrix())
However, you probably want to spit out the probability for every type of weather based on today's weather:
def getTomorrowsProbability(weather):
probMatrix = probabilityMatrix()
return {key[1] : probMatrix[key] for key in probMatrix if key[0] == weather}
print(getTomorrowsProbability('sun'))