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?
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.
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With