code: def center_of_mass(input, labels=None, index=None):
      """
      Calculate the center of mass of the values of an array at labels.
  
      Parameters
      ----------
      input : ndarray
          Data from which to calculate center-of-mass. The masses can either
          be positive or negative.
      labels : ndarray, optional
          Labels for objects in `input`, as generated by `ndimage.label`.
          Only used with `index`. Dimensions must be the same as `input`.
      index : int or sequence of ints, optional
          Labels for which to calculate centers-of-mass. If not specified,
          the combined center of mass of all labels greater than zero
          will be calculated. Only used with `labels`.
  
      Returns
      -------
      center_of_mass : tuple, or list of tuples
          Coordinates of centers-of-mass.
  
      Examples
      --------
      >>> import numpy as np
      >>> a = np.array(([0,0,0,0],
      ...               [0,1,1,0],
      ...               [0,1,1,0],
      ...               [0,1,1,0]))
      >>> from scipy import ndimage
      >>> ndimage.center_of_mass(a)
      (2.0, 1.5)
  
      Calculation of multiple objects in an image
  
      >>> b = np.array(([0,1,1,0],
      ...               [0,1,0,0],
      ...               [0,0,0,0],
      ...               [0,0,1,1],
      ...               [0,0,1,1]))
      >>> lbl = ndimage.label(b)[0]
      >>> ndimage.center_of_mass(b, lbl, [1,2])
      [(0.33333333333333331, 1.3333333333333333), (3.5, 2.5)]
  
      Negative masses are also accepted, which can occur for example when
      bias is removed from measured data due to random noise.
  
      >>> c = np.array(([-1,0,0,0],
      ...               [0,-1,-1,0],
      ...               [0,1,-1,0],
      ...               [0,1,1,0]))
      >>> ndimage.center_of_mass(c)
      (-4.0, 1.0)
  
      If there are division by zero issues, the function does not raise an
      error but rather issues a RuntimeWarning before returning inf and/or NaN.
  
      >>> d = np.array([-1, 1])
      >>> ndimage.center_of_mass(d)
      (inf,)
      """
      normalizer = sum(input, labels, index)
      grids = numpy.ogrid[[slice(0, i) for i in input.shape]]
  
      results = [
          sum(input * grids[dir].astype(float), labels, index)
          / normalizer
          for dir in range(input.ndim)
      ]
  
      if numpy.isscalar(results[0]):
          return tuple(results)
  
      return [tuple(v) for v in numpy.array(results).T]
  
imports: import numpy
  import numpy
  from .None import _ni_support
  from .None import _ni_label
  from .None import _nd_image
  from .None import _morphology
label_desc: Use image node_id 19 for calling a global function with example usage: center_of_mass(input, labels, index) and returns: unknown, tuple