code: def relative_bin_deviation(
      h1, h2
  ):  # 79 us @array, 104 us @list \w 100 bins
      r"""
      Calculate the bin-wise deviation between two histograms.
  
      The relative bin deviation between two histograms :math:`H` and :math:`H'` of size
      :math:`m` is defined as:
  
      .. math::
  
          d_{rbd}(H, H') = \sum_{m=1}^M
              \frac{
                  \sqrt{(H_m - H'_m)^2}
                }{
                  \frac{1}{2}
                  \left(
                      \sqrt{H_m^2} +
                      \sqrt{{H'}_m^2}
                  \right)
                }
  
      *Attributes:*
  
      - a real metric
  
      *Attributes for normalized histograms:*
  
      - :math:`d(H, H')\in[0, \infty)`
      - :math:`d(H, H) = 0`
      - :math:`d(H, H') = d(H', H)`
  
      *Attributes for not-normalized histograms:*
  
      - :math:`d(H, H')\in[0, \infty)`
      - :math:`d(H, H) = 0`
      - :math:`d(H, H') = d(H', H)`
  
      *Attributes for not-equal histograms:*
  
      - not applicable
  
      Parameters
      ----------
      h1 : sequence
          The first histogram.
      h2 : sequence
          The second histogram, same bins as ``h1``.
  
      Returns
      -------
      relative_bin_deviation : float
          Relative bin deviation between the two histograms.
      """
      h1, h2 = __prepare_histogram(h1, h2)
      numerator = scipy.sqrt(scipy.square(h1 - h2))
      denominator = (
          scipy.sqrt(scipy.square(h1)) + scipy.sqrt(scipy.square(h2))
      ) / 2.0
      old_err_state = scipy.seterr(
          invalid="ignore"
      )  # divide through zero only occurs when the bin is zero in both histograms, in which case the division is 0/0 and leads to (and should lead to) 0
      result = numerator / denominator
      scipy.seterr(**old_err_state)
      result[
          scipy.isnan(result)
      ] = 0  # faster than scipy.nan_to_num, which checks for +inf and -inf also
      return scipy.sum(result)
  
imports: import math
  import scipy
label_desc: Use image node_id 11 for calling a global function with example usage: relative_bin_deviation(h1, h2) and returns: scipy