On Thu, Jun 5, 2008 at 4:54 PM, Christopher Marshall <[EMAIL PROTECTED]> wrote: > I will be calculating the mean and variance of a vector with millions of > elements. > > I was wondering how well numpy's mean and variance functions handle the > numerical stability of such a calculation.
How's this for stability? >> import numpy as np >> x = 1e10 * np.ones(100000000) >> x.mean() 10000000000.0 Are you worried that the mean might overflow on the intermediate sum? Yeah, that could be a problem if you are counting stars or bugs in my code: >> x = 1e305 * np.ones(10000000) >> y = x.mean() Warning: overflow encountered in reduce >> y inf But at least you get a warning. _______________________________________________ Numpy-discussion mailing list Numpy-discussion@scipy.org http://projects.scipy.org/mailman/listinfo/numpy-discussion