original_docstring: Return the centroid (center of gravity) for a 2D array.
docstring: Return the centroid (center of gravity) for a 2D array.
docstring_tokens: Return the centroid ( center of gravity ) for a 2D array .
code: def centroid(array_2D):
      """Return the centroid (center of gravity) for a 2D array."""
  
      rows,cols = array_2D.shape
      rsum=0
      csum=0
      rmass_sum=0
      cmass_sum=0
      for r in xrange(rows):
          row_sum = array_2D[r,:].sum()
          rsum += r*row_sum
          rmass_sum += row_sum
  
      for c in xrange(cols):
          col_sum = array_2D[:,c].sum()
          csum += c*col_sum
          cmass_sum += col_sum
  
      row_centroid= rsum/rmass_sum
      col_centroid= csum/cmass_sum
  
      return row_centroid, col_centroid
code_tokens: def centroid ( array_2D ) : rows , cols = array_2D . shape rsum = 0 csum = 0 rmass_sum = 0 cmass_sum = 0 for r in xrange ( rows ) : row_sum = array_2D [ r , : ] . sum ( ) rsum += r * row_sum rmass_sum += row_sum for c in xrange ( cols ) : col_sum = array_2D [ : , c ] . sum ( ) csum += c * col_sum cmass_sum += col_sum row_centroid = rsum / rmass_sum col_centroid = csum / cmass_sum return row_centroid , col_centroid
short_docstring: Return the centroid (center of gravity) for a 2D array.
short_docstring_tokens: Return the centroid ( center of gravity ) for a 2D array .
comment: """Return the centroid (center of gravity) for a 2D array."""