Normalizing a list of numbers in Python

前端 未结 9 1213
北荒
北荒 2020-12-05 06:37

I need to normalize a list of values to fit in a probability distribution, i.e. between 0.0 and 1.0.

I understand how to normalize, but was curious if Pytho

9条回答
  •  忘掉有多难
    2020-12-05 07:11

    Use :

    norm = [float(i)/sum(raw) for i in raw]
    

    to normalize against the sum to ensure that the sum is always 1.0 (or as close to as possible).

    use

    norm = [float(i)/max(raw) for i in raw]
    

    to normalize against the maximum

提交回复
热议问题