[Python] 확률과 통계 계산하기

13644 단어 pythonpython
import numpy as np
from scipy import stats
a = np.array([13, 3, 7, 5, 2, 22, 12, 11, 15])
print(np.size(a))
print(np.sum(a))
print(np.mean(a))
print(np.median(a))
print(stats.mode(a))
print(np.max(a))
print(np.min(a))
print(np.var(a))
print(np.std(a))

9
90
10.0
11.0
ModeResult(mode=array([2]), count=array([1]))
22
2
36.666666666666664
6.0553007081949835

import numpy as np
a = np.array([2200, 2700, 5800, 7500, 11500, 7300, 2700, 3100, 2500, 4300, 2200, 4100])
print((a[0]+a[1]+a[2]+a[3]+a[4]+a[5]+a[6]+a[7]+a[8]+a[9]+a[10]+a[11])/12)
print(np.sum(a)/np.size(a))
print(np.mean(a))

4658.333333333333
4658.333333333333
4658.333333333333

import numpy as np
from scipy.stats.mstats import gmean
a = np.array([2.5, 3.5, 0.8])
print((a[0]*a[1]*a[2])**(1/3))
print(pow((a[0]*a[1]*a[2]), 1/3))
print(pow(np.prod(a), 1/np.size(a)))
print(gmean(a))

1.912931182772389
1.912931182772389
1.912931182772389
1.9129311827723892

import numpy as np
from scipy.stats.mstats import hmean
a = np.array([6, 12])
print(2/(1/a[0]+1/a[1]))
print(np.size(a)/(1/a[0]+1/a[1]))
print(hmean(a))

8.0
8.0
8.0

좋은 웹페이지 즐겨찾기