kcwallace Posted April 28, 2006 Posted April 28, 2006 Does anyone know of a method to calculate the average and standard deviation of a set of numbers in an array other than looping through each element and calculating the average, and then loop through the array for a second time to calculate the standard deviation? Quote Go Beavs!!!
mskeel Posted May 1, 2006 Posted May 1, 2006 Since you have to know the average before you can calculate the standard deviation, I don't think there is a clever way around this. Attempting to calculate as you go would only be a waste of operations. Unless you are talking about millions of elements, I wouldn't think there is much to worry about. One thing you might be able to do to ease the pain, is calculate the sum of all elements as you add/remove them to/from the array. This would alleviate the need to iterate at all. But you will still need to calculate the mean before the standard deviation. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.