code: def weighted_harmonic_mean(
      a: np.ndarray, weights: Optional[np.ndarray] = None
  ) -> np.ndarray:
      """
      Calculate weighted harmonic mean.
  
      :param a:
          the array
      :param weights:
          the weight for individual array members
  
      :return:
          the weighted harmonic mean over the array
  
      .. seealso::
          https://en.wikipedia.org/wiki/Harmonic_mean#Weighted_harmonic_mean
      """
      if weights is None:
          return stats.hmean(a)
  
      # normalize weights
      weights = weights.astype(float)
      weights = weights / weights.sum()
      # calculate weighted harmonic mean
      return np.reciprocal(
          np.average(np.reciprocal(a.astype(float)), weights=weights)
      )
  
imports: from dataclasses import dataclass
  from typing import ClassVar, Collection, Optional
  import numpy
  from docdata import get_docdata
  from scipy import stats
  from ..utils import ExtraReprMixin, camel_to_snake
label_desc: Use image node_id 4 for calling a global function with example usage: weighted_harmonic_mean(a, weights) and returns: np, stats