import numpy as np
P=np.array(([0.5, 0.25, 0, 0.25, 0, 0, 0, 0, 0],
            [0.25, 0.25, 0.25, 0, 0.25, 0, 0, 0, 0],
            [0, 0.25, 0.5, 0, 0, 0.25, 0, 0, 0],
            [0.25, 0, 0, 0.25, 0.25, 0, 0.25, 0, 0],
            [0, 0.25, 0, 0.25, 0, 0.25, 0, 0.25, 0],
            [0, 0, 0.25, 0, 0.25, 0.25, 0, 0, 0.25],
            [0, 0, 0, 0.25, 0, 0, 0.5, 0.25, 0],
            [0, 0, 0, 0, 0.25, 0, 0.25, 0.25, 0.25],
            [0, 0, 0, 0, 0, 0.25, 0, 0.25, 0.5]))
print(P)
Pi=[0]*8+[1]
print(Pi)


def transfer_matrix(Pi):
        S=[0]*9
        for a in range(9):
                S[a]=0
                for b in range(9):
                        S[a]+=P[b, a]*Pi[b]
        return S

for i in range(1000):
        Pi=transfer_matrix(Pi)
        print(Pi)

# After 1000 iterations we get: 
>>> [0.11111111111111109, 0.11111111111111109, 0.1111111111111111, 0.11111111111111109, 0.1111111111111111, 0.11111111111111113, 0.1111111111111111, 0.11111111111111113, 0.11111111111111113]


