def solint_pure_python3(dsref):
start = time.time()
tms = set(dsref.x)
# check if there is something to be averaged at all
if len(tms)==len(dsref.x):
return time.time() - start
# accumulate data into bins of the same time
r = reduce(lambda acc, (tm, y): acc[tm].add(y) or acc, \
itertools.izip(dsref.x, dsref.y), \
collections.defaultdict(average))
# do the averaging
(x, y) = reduce(lambda (xl, yl), (tm, ys): (xl.append(tm) or xl, yl.append(ys.avg()) or yl), \
r.iteritems(), (list(), list()))
dsref.x = x
dsref.y = y
return time.time() - start
评论列表
文章目录