code: def _pcca_connected_isa(evec, n_clusters):
      (n, m) = evec.shape
      if n_clusters > m:
          raise ValueError("Cannot cluster the (" + str(n) + " x " + str(m)
                           + " eigenvector matrix to " + str(n_clusters) + " clusters.")
      diffs = np.abs(np.max(evec, axis=0) - np.min(evec, axis=0))
      assert diffs[0] < 1e-6, "First eigenvector is not constant. This indicates that the transition matrix " \
                              "is not connected or the eigenvectors are incorrectly sorted. Cannot do PCCA."
      assert diffs[1] > 1e-6, "An eigenvector after the first one is constant. " \
                              "Probably the eigenvectors are incorrectly sorted. Cannot do PCCA."
      c = evec[:, list(range(n_clusters))]
      ortho_sys = np.copy(c)
      max_dist = 0.0
      ind = np.zeros(n_clusters, dtype=np.int32)
      for (i, row) in enumerate(c):
          if np.linalg.norm(row, 2) > max_dist:
              max_dist = np.linalg.norm(row, 2)
              ind[0] = i
      ortho_sys -= c[ind[0], None]
      for k in range(1, n_clusters):
          max_dist = 0.0
          temp = np.copy(ortho_sys[ind[k - 1]])
          for (i, row) in enumerate(ortho_sys):
              row -= np.dot(np.dot(temp, np.transpose(row)), temp)
              distt = np.linalg.norm(row, 2)
              if distt > max_dist and i not in ind[0:k]:
                  max_dist = distt
                  ind[k] = i
          ortho_sys /= np.linalg.norm(ortho_sys[ind[k]], 2)
      rot_mat = np.linalg.inv(c[ind])
      chi = np.dot(c, rot_mat)
      return (chi, rot_mat)