code: def rebin(a, newshape):
      
  
      slices = [slice(0, old, float(old)/new)
                for old, new in zip(a.shape, newshape)]
      coordinates = numpy.mgrid[slices]
      # choose the biggest smaller integer index
      indices = coordinates.astype('i')
      return a[tuple(indices)]
docs: Rebin an array to a new shape.