from IPython.display import Image Image('w4.png') mweb={1:[2,3],2:[3],3:[1],4:[3]} T= array([[1./len(mweb[i]) if m in mweb[i] else 0. for m in mweb] for i in mweb]) T around(reduce(dot,[T]*25),3) p=.2 n=len(T) Tp=p*ones([n,n])/n + (1-p)*T Tp linalg.matrix_power(Tp,8) (1/4.)*ones(4).dot(linalg.matrix_power(Tp,8))