Jump to content
Xtreme .Net Talk

Recommended Posts

Posted
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?
Go Beavs!!!
Posted

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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...