首页
/
每日頭條
/
生活
/
如何用python計算方差
如何用python計算方差
更新时间:2024-10-12 10:29:22
前言

在實驗室管理活動中,常常需要開展不确定度評定工作,涉及各項數據的統計及标準差、方差計算,使用python中numpy模塊便可以準确快速地計算。

numpy模塊安裝

pip install numpy

平均值

平均值公式:

如何用python計算方差(Python計算平均值)1

平均值公式

代碼實現—numpy.mean():

import numpy as np value = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] result = np.mean(value) print(result) # 輸出結果 >>>5.5

總體标準差

總體标準差,又稱為理論标準差,計算公式為:

如何用python計算方差(Python計算平均值)2

總體标準差

代碼實現:

import numpy as np value = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] result = np.std(value) print(result) # 輸出結果 >>>2.8722813232690143

樣本标準差

樣本标準差,又稱為無偏标準差,計算公式為:

如何用python計算方差(Python計算平均值)3

樣本标準差

代碼實現:

import numpy as np value = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] result = np.std(value, ddof=1) print(result) # 輸出結果 >>> 3.0276503540974917

方差

方差公式:

如何用python計算方差(Python計算平均值)1

方差公式

代碼實現:

import numpy as np value = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] result = np.var(value) print(result) # 輸出結果 >>>8.25

,
Comments
Welcome to tft每日頭條 comments! Please keep conversations courteous and on-topic. To fosterproductive and respectful conversations, you may see comments from our Community Managers.
Sign up to post
Sort by
Show More Comments
Copyright 2023-2024 - www.tftnews.com All Rights Reserved