本文整理汇总了Python中stats.Stats.sample方法的典型用法代码示例。如果您正苦于以下问题:Python Stats.sample方法的具体用法?Python Stats.sample怎么用?Python Stats.sample使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类stats.Stats
的用法示例。
在下文中一共展示了Stats.sample方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: operations_test
# 需要导入模块: from stats import Stats [as 别名]
# 或者: from stats.Stats import sample [as 别名]
def operations_test():
st = Stats()
for sample in samples:
st.sample(sample)
print st
assert_float_equal(expect.sum, st.sum)
assert_float_equal(expect.sumsq, st.sumsq)
assert_equal(expect.n, st.n)
assert_float_equal(expect.min, st.min)
assert_float_equal(expect.max, st.max)
示例2: one_column
# 需要导入模块: from stats import Stats [as 别名]
# 或者: from stats.Stats import sample [as 别名]
def one_column(filename):
try:
with open(filename) as file:
stats = Stats()
for line in file:
try:
stats.sample(float(line.strip()))
except ValueError as e:
print "File should contains number only, got: %s" % line.strip()
exit(3)
stats.dump()
except IOError as e:
print str(e)
exit(2)
示例3: StatsTests
# 需要导入模块: from stats import Stats [as 别名]
# 或者: from stats.Stats import sample [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)