Nov. 21, 2010
11:43 p.m.
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?