code: def stationary_distribution_from_eigenvector(T):
      r
      val, L = eig(T, left=True, right=False)
  
      """ Sorted eigenvalues and left and right eigenvectors. """
      perm = np.argsort(val)[::-1]
  
      val = val[perm]
      L = L[:, perm]
      """ Make sure that stationary distribution is non-negative and l1-normalized """
      nu = np.abs(L[:, 0])
      mu = nu / np.sum(nu)
      return mu
docs: r"""Compute stationary distribution of stochastic matrix T.
  
      The stationary distribution is the left eigenvector corresponding to the
      non-degenerate eigenvalue :math: `\lambda=1`.
  
      Input:
      ------
      T : numpy array, shape(d,d)
          Transition matrix (stochastic matrix).
  
      Returns
      -------
      mu : numpy array, shape(d,)
          Vector of stationary probabilities.