mean ans std dev of an array?

SpreadTooThin bjobrien62 at gmail.com
Tue Oct 24 14:13:13 EDT 2006


Paul Rubin wrote:
> "SpreadTooThin" <bjobrien62 at gmail.com> writes:
> > print a.mean()
> > print a.std_dev()
> >
> > Is there a way to calculate the mean and standard deviation on array data?
>
> Well, you could use numpy or whatever.  If you want to calculate directly,
> you could do something like (untested):
>
> n = len(a)
> mean = sum(a) / n
> sd = sqrt(sum((x-mean)**2 for x in a) / n)

This last line looks like it will be very slow...
Escpecially if the array is large...
So speed is the real issue here...
If there is a faster way... like transferring the array to a different
container class...
but what?




More information about the Python-list mailing list