赞
踩
摘录的话:AAABBBBAABBCBDBDFDFFFDCDCDE
total:27
A:5 B:8 C:3 D:6 E:1 F:4
现在可得到字符的概率为:5/27,8/27,1/9,2/9,1/27,4/27
熵的计算公式为
H(X) = 2.389172576943942
- import numpy as np
- def ComputEntropy(probX):
- sum = 0.0
- for i in probX:
- sum += i*np.log2(i)
-
- return abs(sum)
-
-
- def main():
- probX = [5/27,8/27,1/9,2/9,1/27,4/27]
- print(ComputEntropy(probX))
- pass
-
- if __name__ == '__main__':
- main()
摘录的话:AAAACCCCDDDDEEEBDDDFFF
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。