def smooth2(x, y, xradius, minsize=0, sort=False): """ return an averaging of x and y using xradius x must be sorted least to greatest """ vlen = len(x) assert vlen == len(y) # simple case if vlen == 0: return [], [] if sort: x, y = util.sort_many(x, y) x2 = [] y2 = [] start = min(x) end = max(x) xtot = x[0] ytot = y[0] low = 0 high = 0 for i in xrange(vlen): xi = x[i] xradius2 = min(xi - start, end - xi, xradius) # move window while x[low] < xi - xradius2: xtot -= x[low] ytot -= y[low] low += 1 while x[high] < xi + xradius2: high += 1 xtot += x[high] ytot += y[high] denom = float(high - low + 1) if denom >= minsize: x2.append(xtot / denom) y2.append(ytot / denom) return x2, y2