code: def weighted_pairwise_distances(X, w, metric='euclidean', w_pow=0.5):
      r
  
      if sklearn is None:
          raise ImportError("This function requires scikit-learn.")
  
      base_metric = sklearn.metrics.pairwise.pairwise_distances(X, metric=metric)
      N = w.shape[0]
      w_matrix = outer_product(w) * N**2
  
      return base_metric / (w_matrix ** w_pow)
docs: r"""
      Given a feature matrix ``X`` with weights ``w``, calculates the modified
      distance metric :math:`\tilde{d}(p, q) = d(p, q) / (w(p) w(q) N^2)^p`, where
      :math:`N` is the length of ``X``. This metric is such that "heavy" feature
      vectors are considered to be closer to each other than "light" feature
      vectors, and are hence correspondingly less likely to be considered part of
      the same cluster.