[Numpy-discussion] [Newbie] Fast plotting
Alan G Isaac
aisaac@american....
Tue Jan 6 09:11:51 CST 2009
A Tuesday 06 January 2009, Franck Pommereau escrigué:
> s = {} # sum of y values for each distinct x (as keys)
> n = {} # number of summed values (same keys)
> for x, y in zip(X, Y) :
> s[x] = s.get(x, 0.0) + y
> n[x] = n.get(x, 0) + 1
Maybe this is not so bad with a couple changes?
from collections import defaultdict
from itertools import izip
s = defaultdict(int) # sum of y values for each distinct x (as keys)
n = defaultdict(int) # number of summed values (same keys)
for x, y in izip(x, y) :
s[x] += y
n[x] += 1
fwiw,
Alan Isaac
More information about the Numpy-discussion
mailing list