欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

使用Python繪制三種概率曲線詳解

 更新時間:2022年03月23日 09:38:54   作者:hhh江月  
這篇文章主要為大家分享了如何利用Python實現(xiàn)概率曲線的繪制,文中繪制了正態(tài)分布的曲線和指數(shù)分布的曲線,感興趣的可以了解一下

曲線一

解釋

這里是使用matplotlib來繪制正態(tài)分布的曲線。

代碼實現(xiàn)

import numpy as np
import matplotlib.pyplot as plt


def test1(n, m=500):
    out = []
    result = np.random.normal(1, 5, n * m)
    print(result)
    for i in range(m):
        average0 = 0
        for j in range(n):
            average0 += result[n * i  + j] 
            if j == n - 1:
                out.append(average0 / n)
                average0 = 0
    print(out)
    
    plt.hist(out,bins=25) 
    plt.title("test (1)")
    plt.xlabel("x")
    plt.ylabel("rate")    
    plt.show()

 
test1(5)

曲線二

解釋

這里使用了matplotlib.pyplot來實現(xiàn)指數(shù)分布的繪制,具體的代碼實現(xiàn)參見下面所示:

代碼實現(xiàn)

import numpy as np
import matplotlib.pyplot as plt

def test2(n, m=500):
    out0 = []
    result0 = np.random.exponential(scale=1, size=n * m)
    # print(result0)
    for i in range(m):
        average000 = 0
        for j in range(n):
            average000 += result0[n * i  + j] 
            if j == n - 1:
                out0.append(average000 / n)
                average000 = 0
    # print(out0)
    
    plt.hist(out0,bins=25)     
    plt.show()
test2(5)

曲線三

代碼實現(xiàn)

import numpy as np
import matplotlib.pyplot as plt
def test3(n1, m111=500):
    out11 = []
    # np.random.standard_t
    result11 = np.random.standard_t(1, size=n1 * m111)
    #  print(result)
    for i in range(m111):
        average0 = 0
        for j in range(n):
            average0 += result11[n1 * i  + j] 
            if j == n - 1:
                out11.append(average0 / n1)
                average0 = 0
    #  print(out11)
    
    plt.hist(out11,bins=20) 
    plt.title("test (3)")   
    plt.show() 
test3(30)

到此這篇關(guān)于使用Python繪制三種概率曲線詳解的文章就介紹到這了,更多相關(guān)Python概率曲線內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評論