# ASP.NET / C# / Math: Remove Extreme Numbers from Array

How can I automatically remove all extreme numbers from an array?

For example,
``````double[] y = {23.2542, 24.25356, 21.89, 25.345, 24.237, 29.2325, 1.52, 99.234, 26.234, 2.53342, 104.2343 };
``````
These numbers are extreme compared to the other numbers in the array:
1.52,
99.234
2.53342
104.2343

A person can look at the numbers in the array and notice that those are extremes, however I would like to use ASP.NET/C# to identify and remove the extreme numbers.
LVL 10
###### Who is Participating?

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Commented:
You could calculate the standard deviation.  Then any values that are +- 2 standard deviations, you can remove from the list.
``````private double getStandardDeviation(List<double> doubleList)
{
double average = doubleList.Average();
double sumOfDerivation = 0;
foreach (double value in doubleList)
{
sumOfDerivation += (value) * (value);
}
double sumOfDerivationAverage = sumOfDerivation / (doubleList.Count - 1);
return Math.Sqrt(sumOfDerivationAverage - (average*average));
}
``````

Experts Exchange Solution brought to you by