code: def find_centroid(cvects, idx_list, weights=None):
      
      if weights is None:
          weighted = cvects.T[idx_list].sum(0)
          sum_weights = float(len(idx_list))
      else:
          weighted = ((cvects * weights).T[idx_list]).sum(0)
          sum_weights = weights.sum(0)
      weighted /= sum_weights
      # make sure it is normalized
      norm = np.sqrt((weighted * weighted).sum())
      weighted /= norm
      return weighted
docs: Find the centroid for a set of vectors
  
      Parameters
      ----------
      cvects : ~numpy.ndarray(3,nsrc) with directional cosine (i.e., x,y,z component) values
  
      idx_list : [int,...]
        list of the source indices in the cluster
  
      weights : ~numpy.ndarray(nsrc) with the weights to use.  None for equal weighting
  
      returns (np.ndarray(3)) with the directional cosine (i.e., x,y,z component) values of the centroid