title: How to efficiently calculate a running standard deviation
body: <p>I have an array of lists of numbers, e.g.:</p>
  <pre><code>[0] (0.01, 0.01, 0.02, 0.04, 0.03)
  [1] (0.00, 0.02, 0.02, 0.03, 0.02)
  [2] (0.01, 0.02, 0.02, 0.03, 0.02)
       ...
  [n] (0.01, 0.00, 0.01, 0.05, 0.03)
  </code></pre>
  <p>I would like to efficiently calculate the mean and standard deviation at each index of a list, across all array elements.</p>
  <p>To do the mean, I have been looping through the array and summing the value at a given index of a list. At the end, I divide each value in my &quot;averages list&quot; by <code>n</code> (I am working with a population, not a sample from the population).</p>
  <p>To do the standard deviation, I loop through again, now that I have the mean calculated.</p>
  <p>I would like to avoid going through the array twice, once for the mean and then once for the standard deviation (after I have a mean).</p>
  <p>Is there an efficient method for calculating both values, only going through the array once? Any code in an interpreted language (e.g., Perl or Python) or pseudocode is fine.</p>