def top_eigenvector(A,niter=<NUM_LIT:1000>,force_iteration=False):
n = A.shape[<NUM_LIT:0>]<EOL>np.seterr(invalid='<STR_LIT>',divide='<STR_LIT>')<EOL>if n <= <NUM_LIT> and not force_iteration:<EOL><INDENT>x = np.repeat(<NUM_LIT:1.>/n,n)<EOL>x = np.linalg.matrix_power(A.T,niter).dot(x)<EOL>x /= x.sum()<EOL>return x<EOL><DEDENT>else:<EOL><INDENT>x1 = np.repeat(<NUM_LIT:1.>/n,n)<EOL>x2 = x1.copy()<EOL>for itr in range(niter):<EOL><INDENT>np.dot(A.T,x1,out=x2)<EOL>x2 /= x2.sum()<EOL>x1,x2 = x2,x1<EOL>if np.linalg.norm(x1-x2) < <NUM_LIT>:<EOL><INDENT>break<EOL><DEDENT><DEDENT>return x1<EOL><DEDENT>
assuming the LEFT invariant subspace of A corresponding to the LEFT
eigenvalue of largest modulus has geometric multiplicity of 1 (trivial
Jordan block), returns the vector at the intersection of that eigenspace and
the simplex

A should probably be a ROW-stochastic matrix

probably uses power iteration