[SciPy-User] memory error - numpy mean - netcdf4

srean srean.list@gmail....
Fri Aug 26 13:00:18 CDT 2011


> Finally, you're getting the MemoryError because you're trying to put an
> ginormous array into memory all at once. Your OS can't handle it. Just loop
> through each time step and keep a running total and counter. Then divide
> your total (which is an array) by your counter (which is an integer or
> float) and presto: you have your average. It's plenty fast, don't worry.
>

In fact one can even avoid keeping the running total. If the values are
integers then the running total may overflow.

Say you have the mean \mu computed from N points and you have a new
collection of m points whose mean is t.
Then the mean on the N + m points is:   \mu_{new} = \mu + (m)/(N+m) ( t -
\mu)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.scipy.org/pipermail/scipy-user/attachments/20110826/6256edb0/attachment.html 


More information about the SciPy-User mailing list