Normalizing a list of numbers in Python

前端 未结 9 1201
北荒
北荒 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:00

    For ones who wanna use scikit-learn, you can use

    from sklearn.preprocessing import normalize
    
    x = [1,2,3,4]
    normalize([x]) # array([[0.18257419, 0.36514837, 0.54772256, 0.73029674]])
    normalize([x], norm="l1") # array([[0.1, 0.2, 0.3, 0.4]])
    normalize([x], norm="max") # array([[0.25, 0.5 , 0.75, 1.]])
    

提交回复
热议问题