首页 > 编程语言 > 详细

一个python的计算熵(entropy)的函数

时间:2016-06-11 14:25:05      阅读:657      评论:0      收藏:0      [点我收藏+]

计算熵的函数:

# -*- coding: utf-8 -*-
import math

#the function to calculate entropy, you should use the probabilities as the parameters
def entropy(*c):
    result=-1;
    if(len(c)>0):
        result=0;
    for x in c:
        result+=(-x)*math.log(x,2)
    return result;
    
if (__name__=="__main__"):
    print(entropy(1/3,2/3));

 

一个python的计算熵(entropy)的函数

原文:http://www.cnblogs.com/vanwoos/p/5575241.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!