本文整理汇总了Python中stats.Stats.mean方法的典型用法代码示例。如果您正苦于以下问题:Python Stats.mean方法的具体用法?Python Stats.mean怎么用?Python Stats.mean使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类stats.Stats
的用法示例。
在下文中一共展示了Stats.mean方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: StatsTests
# 需要导入模块: from stats import Stats [as 别名]
# 或者: from stats.Stats import mean [as 别名]
class StatsTests(unittest.TestCase):
def setUp(self):
self.st = Stats()
self.expect = Stats()
self.expect.sumsq = 425.1641
self.expect.sum = 55.84602
self.expect.min = 0.333
self.expect.max = 9.678
self.expect.n = 10
def test_operations(self):
samples = [
6.1061334, 9.6783204, 1.2747090, 8.2395131, 0.3333483,
6.9755066, 1.0626275, 7.6587523, 4.9382973, 9.5788115
]
for i in samples: self.st.sample(i)
self.st.dump()
self.assertEqual(EQ(self.st.sumsq, self.expect.sumsq, 3), True)
self.assertEqual(EQ(self.st.sum, self.expect.sum, 3), True)
self.assertEqual(EQ(self.st.min, self.expect.min, 3), True)
self.assertEqual(EQ(self.st.max, self.expect.max, 3), True)
self.assertEqual(EQ(self.st.n, self.expect.n, 3), True)
self.assertEqual(EQ(self.expect.mean(), self.st.mean(), 3), True)
self.assertEqual(EQ(self.expect.stdev(), self.st.stdev(), 3), True)
def test_recreate(self):
self.st.recreate( self.expect.sum, self.expect.sumsq, self.expect.n,
self.expect.min, self.expect.max
)
self.assertEqual(self.expect.sum == self.st.sum, True)
self.assertEqual(self.expect.sumsq == self.st.sumsq, True)
self.assertEqual(self.expect.min == self.st.min, True)
self.assertEqual(self.expect.max == self.st.max, True)
self.assertEqual(self.expect.n == self.st.n, True)
self.assertEqual(EQ(self.expect.mean(), self.st.mean(), 3), True)
self.assertEqual(EQ(self.expect.stdev(), self.st.stdev(), 3), True)
示例2: input
# 需要导入模块: from stats import Stats [as 别名]
# 或者: from stats.Stats import mean [as 别名]
#!/usr/bin/python3
# -*- coding: utf-8 -*-
from utils import Utils
from stats import Stats
input()
line = input()
values = line.split()
numbers = [int(i) for i in values]
numbers.sort()
average = Stats.mean(numbers)
median = Stats.median(numbers)
mode = Stats.mode(numbers)
print(Utils.scale(average,1))
print(Utils.scale(median, 1))
print(mode)