How to normalize a list of int values

后端 未结 3 1201
粉色の甜心
粉色の甜心 2020-12-16 02:53

I have a list of int values:

List histogram;

How do I normalize all values so that the max value in the

3条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-16 03:36

    Iterate though, find the maximum value (call it MAXVAL), then iterate through once more and multiply every value in the list by (100/MAXVAL).

    var ratio = 100.0 / list.Max();
    var normalizedList = list.Select(i => i * ratio).ToList();
    

提交回复
热议问题