Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to normalize a list of int values

Tags:

c#

.net

I have a list of int values:

List<int> histogram;

How do I normalize all values so that the max value in the list is always 100?

like image 964
hbruce Avatar asked Aug 04 '09 09:08

hbruce


People also ask

How do you normalize a list of values?

the Formula for Normalization We subtract the minimum value from every number and divide it by the range i-e: max-min. So, in output, we get the normalized value of that specific number.


1 Answers

To normalize a set of numbers that may contain negative values,
and to define the normalized scale's range:

List<int> list = new List<int>{-5,-4,-3,-2,-1,0,1,2,3,4,5};
double scaleMin = -1; //the normalized minimum desired
double scaleMax = 1; //the normalized maximum desired

double valueMax = list.Max();
double valueMin = list.Min();
double valueRange = valueMax - valueMin;
double scaleRange = scaleMax - scaleMin;

IEnumerable<double> normalized = 
    list.Select (i =>
        ((scaleRange * (i - valueMin))
            / valueRange)
        + scaleMin);
like image 96
zomf Avatar answered Sep 28 '22 06:09

zomf