小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

python做頻率統(tǒng)計圖 完整版

 昵稱QAb6ICvc 2021-12-06


 分類: Python/Ruby

# your code goes here

from matplotlib import pyplot as plt

import pandas as pd

def linearCongruentialMethod(Xo, m, a, c, randomNums, U):

    randomNums[0] = Xo

    U[0] = randomNums[0] / m

    for i in range(1, 10000):

        # Follow the linear congruential method

        randomNums[i] = ((randomNums[i - 1] * a) + c) % m

        U[i] = randomNums[i] / m

print("a = 1597, b = 0, m = 244944")

a = 1597

c = 0

m = 244944

i = 0.01

for i in range(1, 6):

    X0 = i * 0.01

    print("\n X0 = ", X0, "\n")

    noOfRandomNums = 10005

    randomNums = [0] * (noOfRandomNums)

    U = [0] * (noOfRandomNums)

    linearCongruentialMethod(X0, m, a, c, randomNums, U)

    intervals = 20

    freq = [0] * (intervals)

    for j in U:

        x = 1

        x = j * 100 / 5

        freq[int(x)] = freq[int(x)] + 1

    mydata = {'Interval  ': ['[0.00,0.05)', '[0.05,0.10)', '[0.10,0.15)', '[0.15,0.20)', '[0.20,0.25)', '[0.25,0.30)',

                             '[0.30,0.35)', '[0.35,0.40)', '[0.40,0.45)', '[0.45,0.50)', '[0.50,0.55)', '[0.55,0.60)',

                             '[0.60,0.65)', '[0.65,0.70)', '[0.70,0.75)', '[0.75,0.80)', '[0.80,0.85)', '[0.85,0.90)',

                             '[0.90,0.95)', '[0.95,1.00)'],

              'Freuency': freq}

    df = pd.DataFrame(mydata)

    print(df)

    data = {'1': freq[0], '2': freq[1], '3': freq[2], '4': freq[3], '5': freq[4], '6': freq[5], '7': freq[6],

            '8': freq[7], '9': freq[8], '10': freq[9], '11': freq[10], '12': freq[11], '13': freq[12], '14': freq[13],

            '15': freq[14], '16': freq[15], '17': freq[16], '18': freq[17], '19': freq[18], '20': freq[19], }

    interval = list(data.keys())

    frequency = list(data.values())

    fig = plt.figure(figsize=(10, 5))

    plt.bar(interval, frequency, color='maroon', width=0.4)

    plt.show()

print("\na = 51749, b = 0, m = 244944")

a = 51749

c = 0

m = 244944

i = 0.01

for i in range(1, 6):

    X0 = i * 0.01

    print("\n X0 = ", X0, "\n")

    noOfRandomNums = 10005

    randomNums = [0] * (noOfRandomNums)

    U = [0] * (noOfRandomNums)

    linearCongruentialMethod(X0, m, a, c, randomNums, U)

    intervals = 20

    freq = [0] * (intervals)

    for j in U:

        x = 1

        x = j * 100 / 5

        freq[int(x)] = freq[int(x)] + 1

    mydata = {'Interval  ': ['[0.00,0.05)', '[0.05,0.10)', '[0.10,0.15)', '[0.15,0.20)', '[0.20,0.25)', '[0.25,0.30)',

                             '[0.30,0.35)', '[0.35,0.40)', '[0.40,0.45)', '[0.45,0.50)', '[0.50,0.55)', '[0.55,0.60)',

                             '[0.60,0.65)', '[0.65,0.70)', '[0.70,0.75)', '[0.75,0.80)', '[0.80,0.85)', '[0.85,0.90)',

                             '[0.90,0.95)', '[0.95,1.00)'],

              'Freuency': freq}

    df = pd.DataFrame(mydata)

    print(df)

    data = {'1': freq[0], '2': freq[1], '3': freq[2], '4': freq[3], '5': freq[4], '6': freq[5], '7': freq[6],

            '8': freq[7], '9': freq[8], '10': freq[9], '11': freq[10], '12': freq[11], '13': freq[12], '14': freq[13],

            '15': freq[14], '16': freq[15], '17': freq[16], '18': freq[17], '19': freq[18], '20': freq[19], }

    interval = list(data.keys())

    frequency = list(data.values())

    fig = plt.figure(figsize=(10, 5))

    plt.bar(interval, frequency, color='blue', width=0.4)

    plt.show()

    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多