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
_______________________________________________
Numpy-discussion mailing list
Numpy-discussion@scipy.org
http://projects.scipy.org/mailman/listinfo/numpy-discussion

Reply via email to