import numpy as np R0=0.6 S0=0.4 R1=R0*0.1 S1=S0*0.6 l=np.array([[0.4,0.3], [0.5,0.1]]) tran=np.array([[0.7,0.4], #R-R R-S [0.3,0.6]]) #S-R S-S p1=R1*l[0,0]*tran[0,0] #R-R p2=S1*l[0,0]*tran[0,1] #S-R p3=R1*l[0,1]*tran[1,0] #R-S p4=S1*l[0,1]*tran[1,1] #S-S pp1=max(p1,p2) pp2=max(p3,p4) if p1>p2 and p3>p4: print("rainy") else: print("sunny") print(pp1,pp2) sunny 0.038400000000000004 0.043199999999999995 t1=pp1*l[1,0]*tran[0,0] t2=pp1*l[1,1]*tran[1,0] t3=pp2*l[1,0]*tran[0,1] t4=pp2*l[1,1]*tran[1,1] max1=max(t1,t2,t3,t4) if t1>t2 and t3>t4: print("rainy") else: print("sunny") if t1>t3 or t1>t4 or t2>t3 or t2>t3: print("rainy") else: print("sunny") print(max1) rainy rainy 0.01344