在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 教程/ 數(shù)據(jù)分析&挖掘/ NumPy統(tǒng)計函數(shù)
NumPy位操作
NumPy數(shù)學(xué)算數(shù)函數(shù)
NumPy高級索引
NumPy環(huán)境安裝配置
NumPy IO文件操作
NumPy字符串函數(shù)
NumPy切片和索引
NumPy統(tǒng)計函數(shù)
NumPy矩陣庫
NumPy數(shù)組創(chuàng)建例程
NumPy線性代數(shù)
NumPy Matplotlib庫
NumPy教程
NumPy排序、搜索和計數(shù)函數(shù)
NumPy字節(jié)交換
NumPy Ndarray對象
NumPy數(shù)組操作
NumPy使用 Matplotlib 繪制直方圖
NumPy數(shù)組屬性
NumPy廣播
NumPy來自現(xiàn)有數(shù)據(jù)的數(shù)組
NumPy副本和視圖
NumPy在數(shù)組上的迭代
NumPy來自數(shù)值范圍的數(shù)組
NumPy算數(shù)運(yùn)算
NumPy數(shù)據(jù)類型

NumPy統(tǒng)計函數(shù)

NumPy - 統(tǒng)計函數(shù)

NumPy 有很多有用的統(tǒng)計函數(shù),用于從數(shù)組中給定的元素中查找最小,最大,百分標(biāo)準(zhǔn)差和方差等。 函數(shù)說明如下:

numpy.amin()numpy.amax()

這些函數(shù)從給定數(shù)組中的元素沿指定軸返回最小值和最大值。

示例

import numpy as np 
a = np.array([[3,7,5],[8,4,3],[2,4,9]])  
print  '我們的數(shù)組是:'  
print a 
print  '\n'  
print  '調(diào)用 amin() 函數(shù):'  
print np.amin(a,1)  
print  '\n'  
print  '再次調(diào)用 amin() 函數(shù):'  
print np.amin(a,0)  
print  '\n'  
print  '調(diào)用 amax() 函數(shù):'  
print np.amax(a)  
print  '\n'  
print  '再次調(diào)用 amax() 函數(shù):'  
print np.amax(a, axis =  0)

輸出如下:

我們的數(shù)組是:
[[3 7 5]
[8 4 3]
[2 4 9]]

調(diào)用 amin() 函數(shù):
[3 3 2]

再次調(diào)用 amin() 函數(shù):
[2 4 3]

調(diào)用 amax() 函數(shù):
9

再次調(diào)用 amax() 函數(shù):
[8 7 9]

numpy.ptp()

numpy.ptp()函數(shù)返回沿軸的值的范圍(最大值 - 最小值)。

import numpy as np 
a = np.array([[3,7,5],[8,4,3],[2,4,9]])  
print  '我們的數(shù)組是:'  
print a 
print  '\n'  
print  '調(diào)用 ptp() 函數(shù):'  
print np.ptp(a)  
print  '\n'  
print  '沿軸 1 調(diào)用 ptp() 函數(shù):'  
print np.ptp(a, axis =  1)  
print  '\n'  
print  '沿軸 0 調(diào)用 ptp() 函數(shù):'  
print np.ptp(a, axis =  0)

輸出如下:

我們的數(shù)組是:
[[3 7 5]
[8 4 3]
[2 4 9]]

調(diào)用 ptp() 函數(shù):
7

沿軸 1 調(diào)用 ptp() 函數(shù):
[4 5 7]

沿軸 0 調(diào)用 ptp() 函數(shù):
[6 3 6]

numpy.percentile()

百分位數(shù)是統(tǒng)計中使用的度量,表示小于這個值得觀察值占某個百分比。 函數(shù)numpy.percentile()接受以下參數(shù)。

numpy.percentile(a, q, axis)

其中:

序號 參數(shù)及描述
1. a 輸入數(shù)組
2. q 要計算的百分位數(shù),在 0 ~ 100 之間
3. axis 沿著它計算百分位數(shù)的軸

示例

import numpy as np 
a = np.array([[30,40,70],[80,20,10],[50,90,60]])  
print  '我們的數(shù)組是:'  
print a 
print  '\n'  
print  '調(diào)用 percentile() 函數(shù):'  
print np.percentile(a,50)  
print  '\n'  
print  '沿軸 1 調(diào)用 percentile() 函數(shù):'  
print np.percentile(a,50, axis =  1)  
print  '\n'  
print  '沿軸 0 調(diào)用 percentile() 函數(shù):'  
print np.percentile(a,50, axis =  0)

輸出如下:

我們的數(shù)組是:
[[30 40 70]
 [80 20 10]
 [50 90 60]]

調(diào)用 percentile() 函數(shù):
50.0

沿軸 1 調(diào)用 percentile() 函數(shù):
[ 40. 20. 60.]

沿軸 0 調(diào)用 percentile() 函數(shù):
[ 50. 40. 60.]

numpy.median()

中值定義為將數(shù)據(jù)樣本的上半部分與下半部分分開的值。 numpy.median()函數(shù)的用法如下面的程序所示。

示例

import numpy as np 
a = np.array([[30,65,70],[80,95,10],[50,90,60]])  
print  '我們的數(shù)組是:'  
print a 
print  '\n'  
print  '調(diào)用 median() 函數(shù):'  
print np.median(a)  
print  '\n'  
print  '沿軸 0 調(diào)用 median() 函數(shù):'  
print np.median(a, axis =  0)  
print  '\n'  
print  '沿軸 1 調(diào)用 median() 函數(shù):'  
print np.median(a, axis =  1)

輸出如下:

我們的數(shù)組是:
[[30 65 70]
 [80 95 10]
 [50 90 60]]

調(diào)用 median() 函數(shù):
65.0

沿軸 0 調(diào)用 median() 函數(shù):
[ 50. 90. 60.]

沿軸 1 調(diào)用 median() 函數(shù):
[ 65. 80. 60.]

numpy.mean()

算術(shù)平均值是沿軸的元素的總和除以元素的數(shù)量。 numpy.mean()函數(shù)返回數(shù)組中元素的算術(shù)平均值。 如果提供了軸,則沿其計算。

示例

import numpy as np 
a = np.array([[1,2,3],[3,4,5],[4,5,6]])  
print  '我們的數(shù)組是:'  
print a 
print  '\n'  
print  '調(diào)用 mean() 函數(shù):'  
print np.mean(a)  
print  '\n'  
print  '沿軸 0 調(diào)用 mean() 函數(shù):'  
print np.mean(a, axis =  0)  
print  '\n'  
print  '沿軸 1 調(diào)用 mean() 函數(shù):'  
print np.mean(a, axis =  1)

輸出如下:

我們的數(shù)組是:
[[1 2 3]
 [3 4 5]
 [4 5 6]]

調(diào)用 mean() 函數(shù):
3.66666666667

沿軸 0 調(diào)用 mean() 函數(shù):
[ 2.66666667 3.66666667 4.66666667]

沿軸 1 調(diào)用 mean() 函數(shù):
[ 2. 4. 5.]

numpy.average()

加權(quán)平均值是由每個分量乘以反映其重要性的因子得到的平均值。 numpy.average()函數(shù)根據(jù)在另一個數(shù)組中給出的各自的權(quán)重計算數(shù)組中元素的加權(quán)平均值。 該函數(shù)可以接受一個軸參數(shù)。 如果沒有指定軸,則數(shù)組會被展開。

考慮數(shù)組[1,2,3,4]和相應(yīng)的權(quán)重[4,3,2,1],通過將相應(yīng)元素的乘積相加,并將和除以權(quán)重的和,來計算加權(quán)平均值。

加權(quán)平均值 = (1*4+2*3+3*2+4*1)/(4+3+2+1)

示例

import numpy as np 
a = np.array([1,2,3,4])  
print  '我們的數(shù)組是:'  
print a 
print  '\n'  
print  '調(diào)用 average() 函數(shù):'  
print np.average(a)  
print  '\n'  
# 不指定權(quán)重時相當(dāng)于 mean 函數(shù)
wts = np.array([4,3,2,1])  
print  '再次調(diào)用 average() 函數(shù):'  
print np.average(a,weights = wts)  
print  '\n'  
# 如果 returned 參數(shù)設(shè)為 true,則返回權(quán)重的和  
print  '權(quán)重的和:'  
print np.average([1,2,3,  4],weights =  [4,3,2,1], returned =  True)

輸出如下:

我們的數(shù)組是:
[1 2 3 4]

調(diào)用 average() 函數(shù):
2.5

再次調(diào)用 average() 函數(shù):
2.0

權(quán)重的和:
(2.0, 10.0)

在多維數(shù)組中,可以指定用于計算的軸。

示例

import numpy as np 
a = np.arange(6).reshape(3,2)  
print  '我們的數(shù)組是:'  
print a 
print  '\n'  
print  '修改后的數(shù)組:' 
wt = np.array([3,5])  
print np.average(a, axis =  1, weights = wt)  
print  '\n'  
print  '修改后的數(shù)組:'  
print np.average(a, axis =  1, weights = wt, returned =  True)

輸出如下:

我們的數(shù)組是:
[[0 1]
 [2 3]
 [4 5]]

修改后的數(shù)組:
[ 0.625 2.625 4.625]

修改后的數(shù)組:
(array([ 0.625, 2.625, 4.625]), array([ 8., 8., 8.]))

標(biāo)準(zhǔn)差

標(biāo)準(zhǔn)差是與均值的偏差的平方的平均值的平方根。 標(biāo)準(zhǔn)差公式如下:

std = sqrt(mean((x - x.mean())**2))

如果數(shù)組是[1,2,3,4],則其平均值為2.5。 因此,差的平方是[2.25,0.25,0.25,2.25],并且其平均值的平方根除以4,即sqrt(5/4)1.1180339887498949。

示例

import numpy as np 
print np.std([1,2,3,4])

輸出如下:

1.1180339887498949

方差

方差是偏差的平方的平均值,即mean((x - x.mean())** 2)。 換句話說,標(biāo)準(zhǔn)差是方差的平方根。

示例

import numpy as np 
print np.var([1,2,3,4])

輸出如下:

1.25