美文网首页
常用小轮子

常用小轮子

作者: Traeyee | 来源:发表于2017-01-09 00:19 被阅读0次

english_punctuations = [',', '.', ':', ';', '?', '(', ')', '[', ']', '&', '!', '*', '@', '#', '$', '%']

re_han_default = re.compile("([\u4E00-\u9FD5a-zA-Z0-9+#&._]+)", re.U)
re_skip_default = re.compile("(\r\n|\s)", re.U)

泊松分布

def poisson(L):  
    """ 
    poisson distribution 
    return a integer random number, L is the mean value 
    """  
    p = 1.0  
    k = 0  
    e = math.exp(-L)  
    while p >= e:  
        u = random.random()  #generate a random floating point number in the range [0.0, 1.0)  
        p *= u  
        k += 1  
    return k-1  

负指数分布

def expntl(L):  
    """ 
    negative exponential distribution 
    return a double random number, L is the mean value 
    """  
    u = random.random()  
    return -L * math.log(u)  

相关文章

网友评论

      本文标题:常用小轮子

      本文链接:https://www.haomeiwen.com/subject/jpucbttx.html