2016-03-27   python 

Python写経(統計)

参照

http://docs.python.jp/3/library/statistics.html#module-statistics

statistics, mean, median, mode

import statistics as st

s = [3, 1, 4, 1, 5, 9]
print('データ = ', s)
print('平均値 = ', st.mean(s))
print('中央値 = ', st.median(s))
print('最頻値 = ', st.mode(s))
データ =  [3, 1, 4, 1, 5, 9]
平均値 =  3.8333333333333335
中央値 =  3.5
最頻値 =  1

from, import

from statistics import mean, median, mode

s = [3, 1, 4, 1, 5, 9]
print('データ = ', s)
print('平均値 = ', mean(s))
print('中央値 = ', median(s))
print('最頻値 = ', mode(s))

これはやりすぎ

from statistics import mean as 平均値
from statistics import median as 中央値
from statistics import mode as 最頻値

s = [3, 1, 4, 1, 5, 9]
print('データ = ', s)
print('平均値 = ', 平均値(s))
print('中央値 = ', 中央値(s))
print('最頻値 = ', 最頻値(s))

謝辞

https://twitter.com/hyuki/status/714042600550834176 https://twitter.com/momijipan/status/714044960949927936 https://twitter.com/hogelog/status/714045072203853829 https://twitter.com/methane/status/714046217106292736

 2016-03-27   python