在 Python 中规范化数字列表 [英] Normalizing a list of numbers in Python
本文介绍了在 Python 中规范化数字列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要对一系列值进行归一化以适应概率分布,即介于 0.0 和 1.0 之间.
I need to normalize a list of values to fit in a probability distribution, i.e. between 0.0 and 1.0.
我了解如何规范化,但很好奇 Python 是否具有自动执行此操作的功能.
I understand how to normalize, but was curious if Python had a function to automate this.
我想从:
raw = [0.07, 0.14, 0.07]
到
normed = [0.25, 0.50, 0.25]
推荐答案
使用 :
norm = [float(i)/sum(raw) for i in raw]
针对总和进行标准化以确保总和始终为 1.0(或尽可能接近).
to normalize against the sum to ensure that the sum is always 1.0 (or as close to as possible).
使用
norm = [float(i)/max(raw) for i in raw]
针对最大值进行标准化
这篇关于在 Python 中规范化数字列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文