import numpy
import random
import math
def variance1(nums):
"""Calculates variance using the one pass method."""
# Put your code here
def variance2(nums):
"""Calculates variance using the two pass method."""
# Put your code here
def variance_test(nums):
"""Runs the three variance algorithms and prints results."""
one_var = variance1(nums)
two_var = variance2(nums)
numpy_var = numpy.var(nums, ddof=1)
print 'Mean: ', numpy.mean(nums)
print 'One pass variance:', one_var
print 'Two pass variance:', two_var
print 'NumPy variance: ', numpy_var
print
if __name__ == '__main__':
# Put your code for the two tests here
# This is the third part where you answer the question as to why the one
# pass method is incorrect. Hint: Look at how the numbers change.
print '*' * 80
N = 5
nums = numpy.zeros(N)
for i in xrange(N):
nums[i] = random.uniform(0, 20) + 100
for y in xrange(3, 12):
print nums
variance_test(nums)
for i in xrange(N):
nums[i] += 10**y - 10**(y-1)