<[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > > >> n = len(a) > >> mean = sum(a) / n > >> sd = sqrt(sum((x-mean)**2 for x in a) / n) > ... > >> If there is a faster way... like transferring the array to a > >> different container class... but what? > > Perhaps: > > >>> import scipy > >>> print scipy.mean([1,2,3,4,5,6]) > 3.5 > >>> print scipy.std([1,2,3,4,5,6]) > 1.87082869339 > > Skip
Can scipy work with an iterator/generator? If you can only make one pass through the data, you can try this: lst = (random.gauss(0,10) for i in range(1000)) # compute n, sum(x), and sum(x**2) with single pass through list n,sumx,sumx2 = reduce(lambda a,b:(a[0]+b[0],a[1]+b[1],a[2]+b[2]), ((1,x,x*x) for x in lst) ) sd = sqrt( (sumx2 - (sumx*sumx/n))/(n-1) ) -- Paul -- http://mail.python.org/mailman/listinfo/python-list