code: def pdist(x, metric):
      
  
      if isinstance(metric, str):
          import scipy.spatial
          if hasattr(scipy.spatial.distance, metric):
              metric = getattr(scipy.spatial.distance, metric)
          else:
              raise ValueError('metric name not found')
  
      m = x.shape[1]
      dist = list()
      for i, j in itertools.combinations(range(m), 2):
          a = x[:, i, ...]
          b = x[:, j, ...]
          d = metric(a, b)
          dist.append(d)
      return np.array(dist)
docs: Alternative implementation of :func:`scipy.spatial.distance.pdist`
      which is slower but more flexible in that arrays with >2 dimensions can be
      passed, allowing for multidimensional observations, e.g., diploid
      genotype calls or allele counts.
  
      Parameters
      ----------
      x : array_like, shape (n, m, ...)
          Array of m observations (e.g., samples or haplotypes) in a space
          with n dimensions (e.g., variants). Note that the order of the first
          two dimensions is **swapped** compared to what is expected by
          scipy.spatial.distance.pdist.
      metric : string or function
          Distance metric. See documentation for the function
          :func:`scipy.spatial.distance.pdist` for a list of built-in
          distance metrics.
  
      Returns
      -------
      dist : ndarray
          Distance matrix in condensed form.