[Numpy-discussion] Does np.std() make two passes through the data?

Robert Kern robert.kern@gmail....
Sun Nov 21 19:56:36 CST 2010


On Sun, Nov 21, 2010 at 19:49, Keith Goodman <kwgoodman@gmail.com> wrote:

> But this sample gives a difference:
>
>>> a = np.random.rand(100)
>>> a.var()
>   0.080232196646619805
>>> var(a)
>   0.080232196646619791
>
> As you know, I'm trying to make a drop-in replacement for
> scipy.stats.nanstd. Maybe I'll have to add an asterisk to the drop-in
> part. Either that, or suck it up and store the damn mean.

The difference is less than eps. Quite possibly, the one-pass version
is even closer to the true value than the two-pass version.

-- 
Robert Kern

"I have come to believe that the whole world is an enigma, a harmless
enigma that is made terrible by our own mad attempt to interpret it as
though it had an underlying truth."
  -- Umberto Eco


More information about the NumPy-Discussion mailing list