new_contents: import numpy as np
  
  def weighted_mode(a, w, axis):
      """Returns an array of the weighted modal (most common) value in the
      passed array.
  
      If there is more than one such value, only the first is returned.
      The bin-count for the modal bins is also returned.
  
      This is an extension of the algorithm in scipy.stats.mode.
  
      Parameters
      ----------
      a : array_like
          n-dimensional array of which to find mode(s).
      w : array_like
          n-dimensional array of weights for each value
      axis : int, optional
          Axis along which to operate. Default is 0, i.e. the first axis.
  
      Returns
      -------
      vals : ndarray
          Array of modal values.
      score : ndarray
          Array of weighted counts for each mode.
  
      See Also
      --------
      scipy.stats.mode
      """
      if axis is None:
          a = np.ravel(a)
          axis = 0
      else:
          a = np.asarray(a)
          axis = axis
      
      if a.shape != w.shape:
          w = np.zeros(a.shape, dtype=w.dtype) + w
  
      scores = np.unique(np.ravel(a))       # get ALL unique values
      testshape = list(a.shape)
      testshape[axis] = 1
      oldmostfreq = np.zeros(testshape)
      oldcounts = np.zeros(testshape)
      for score in scores:
          template = np.zeros(a.shape)
          ind = (a == score)
          template[ind] = w[ind]
          counts = np.expand_dims(np.sum(template, axis),axis)
          mostfrequent = np.where(counts > oldcounts, score, oldmostfreq)
          oldcounts = np.maximum(counts, oldcounts)
          oldmostfreq = mostfrequent
      return mostfrequent, oldcounts
  
subject: add neighbors/tools to commit