[Numpy-discussion] Does np.std() make two passes through the data?
Keith Goodman
kwgoodman@gmail....
Sun Nov 21 17:43:12 CST 2010
Does np.std() make two passes through the data?
Numpy:
>> arr = np.random.rand(10)
>> arr.std()
0.3008736260967052
Looks like an algorithm that makes one pass through the data (one for
loop) wouldn't match arr.std():
>> np.sqrt((arr*arr).mean() - arr.mean()**2)
0.30087362609670526
But a slower two-pass algorithm would match arr.std():
>> np.sqrt(((arr - arr.mean())**2).mean())
0.3008736260967052
Is there a way to get the same result as arr.std() in one pass (cython
for loop) of the data?
More information about the NumPy-Discussion
mailing list