code: def pcoa(dist):
      
      import scipy.linalg
  
      # This implementation is based on the skbio.math.stats.ordination.PCoA
      # implementation, with some minor adjustments.
  
      # check inputs
      dist = ensure_square(dist)
  
      # perform scaling
      e_matrix = (dist ** 2) / -2
      row_means = np.mean(e_matrix, axis=1, keepdims=True)
      col_means = np.mean(e_matrix, axis=0, keepdims=True)
      matrix_mean = np.mean(e_matrix)
      f_matrix = e_matrix - row_means - col_means + matrix_mean
      eigvals, eigvecs = scipy.linalg.eigh(f_matrix)
  
      # deal with eigvals close to zero
      close_to_zero = np.isclose(eigvals, 0)
      eigvals[close_to_zero] = 0
  
      # sort descending
      idxs = eigvals.argsort()[::-1]
      eigvals = eigvals[idxs]
      eigvecs = eigvecs[:, idxs]
  
      # keep only positive eigenvalues
      keep = eigvals >= 0
      eigvecs = eigvecs[:, keep]
      eigvals = eigvals[keep]
  
      # compute coordinates
      coords = eigvecs * np.sqrt(eigvals)
  
      # compute ratio explained
      explained_ratio = eigvals / eigvals.sum()
  
      return coords, explained_ratio
docs: Perform principal coordinate analysis of a distance matrix, a.k.a.
      classical multi-dimensional scaling.
  
      Parameters
      ----------
      dist : array_like
          Distance matrix in condensed form.
  
      Returns
      -------
      coords : ndarray, shape (n_samples, n_dimensions)
          Transformed coordinates for the samples.
      explained_ratio : ndarray, shape (n_dimensions)
          Variance explained by each dimension.