[Numpy-discussion] [Newbie] Fast plotting
Franck Pommereau
pommereau@univ-paris12...
Tue Jan 6 03:35:01 CST 2009
Hi all, and happy new year!
I'm new to NumPy and searching a way to compute from a set of points
(x,y) the mean value of y values associated to each distinct x value.
Each point corresponds to a measure in a benchmark (x = parameter, y =
computation time) and I'd like to plot the graph of mean computation
time wrt parameter values. (I know how to plot, but not how to compute
mean values.)
My points are stored as two arrays X, Y (same size).
In pure Python, I'd do as follows:
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
new_x = array(list(sorted(s)))
new_y = array([s[x]/n[x] for x in sorted(s)])
Unfortunately, this code is much too slow because my arrays have
millions of elements. But I'm pretty sure that NumPy offers a way to
handle this more elegantly and much faster.
As a bonus, I'd be happy if the solution would allow me to compute also
standard deviation, min, max, etc.
Thanks in advance for any help!
Franck
More information about the Numpy-discussion
mailing list