常用小轮子

字数 39阅读 86

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)  

推荐阅读更多精彩内容