def covariance(xVec, yVec): #tester = np.vstack((xVec,yVec)) n=len(xVec) xBar = mean(xVec) yBar = mean(yVec) covar = 0; for i in range(0,n): covar += float((xVec[i]-xBar)*(yVec[i]-yBar)) #print("The python covariance is " + str(np.cov(tester))) #print("The N covariance is: " + str(covar/n)) return covar/(n-1) #The sample covariance
def test_complex(): # given that complex numbers are an unordered field # the arithmetic mean of complex numbers is meaningless num_list = [2 + 3j, 3 + 4j, -32 - 2j] obs = mean(num_list) exp = NotImplemented assert obs == exp
def test_ints(): # test caculating the mean of ints num_list = [1, 2, 3, 4, 5] obs = mean(num_list) exp = 3 assert obs == exp
def test_neg(): nums = [ -1, 1, ] obs = mean(nums) exp = 0 assert obs == exp
def test_zero(): num_list=[0,2,4,6] obs = mean(num_list) exp = 3 assert obs == exp
def test_neg(): num_list = [-1, 1] obs = mean(num_list) exp = 0 assert obs == exp
def test_long(): big = 100000000 obs = mean(range(1,big)) exp = big/2.0 assert obs == exp
def test_ints(): num_list = [1,2,3,4,5] obs = mean(num_list) exp = 3 assert obs == exp
def test_neg(): num_list = [3, 4, 8, -3] obs = 3 exp = mean(num_list) assert obs == exp
def test_mean_1234(): values=[1.,2.,3.,4.] calc_mean= mean(values) expected_mean=2.5 assert expected_mean==calc_mean
def test_neg(): num = [4, -3, 5] obs = mean(num) exp = 2 assert obs == exp
def test_zero(): num = [4, 0, 6] obs = mean(num) exp = 3 assert obs == exp
def test_double(): num_list=[1,2,3,4] obs = mean(num_list) exp = 2.5 assert obs == exp
def test_zero(): num_list = [0., 2., 4., 6.] obs = mean(num_list) exp = 3 assert obs == exp
import statistics import mean import sys i = 0 a_numbers = [] for argv in sys.argv: a_numbers.append(sys.argv[i]) i = i+0 del a_numbers[0] print("mean:" (mean(a_numbers))
def test_long(): big = 1000000 obs = mean(range(1, big)) exp = big / 2.0 assert_almost_equal(obs, exp)
def test_ints(): num = [4, 3, 6] obs = mean(num) exp = 4 assert obs == exp
def sSE(yhat,y): ybar = mean(y) sse = 0 for i in range(0,len(yhat)): sse += (yhat[i]-ybar)**2 return sse
def test_negative(): nums = [-3, 0, 0] obs = mean(nums) exp = -1 assert obs == exp
def test_ints(): num_list = [2, 3, 4] obs = 3 exp = mean(num_list) assert obs == exp
def test_empty(): nums = [] obs = mean(nums) assert math.isnan(obs)
def test_double(): # This one will fail in Python 2 num_list=[1,2,3,4] obs = mean(num_list) exp = 2.5 assert obs == exp
def test_mean_1234(): values = [1., 2., 3., 4.] calc_mean = mean(values) expected_mean = 2.5 assert expected_mean == calc_mean
def test_mean_1234(): num_list = [1,2,3,4] calc_mean = mean(num_list) expected_mean = 2.5 assert expected_mean == calc_mean
def test_ints(): num_list = [4, 5, 28, 3] obs = mean(num_list) exp = 10 assert obs == exp
def test_zero(): num_list = [0, 3, 3] obs = mean(num_list) exp = 2 assert obs == exp
def testZero(): nums = [0, 0, 0] obs = mean(nums) exp = 0 assert obs == exp
def test_ints(): num_list = [3, 4, 5] obs = mean(num_list) exp = 4 assert obs == exp
def test1(): list = [0, 4, 5] obs = mean(list) exp = 3 assert obs == exp
def testNeg(): nums = [-1, -1, -1] obs = mean(nums) exp = -1 assert obs == exp
def test_zero(): num_list=[0.,2.,4.,6.] obs = mean(num_list) exp = 3 assert obs == exp
def test_mean_1234(): num_list = [1, 2, 3, 4, 5] calc_mean = mean(num_list) expected_mean = 3 assert expected_mean == calc_mean
def testInts(): nums = [4, 5, 28, 3] obs = mean(nums) exp = 10 assert obs == exp
def test(): list = [3, 4, 5] obs = mean(list) exp = 4 assert obs == exp
def test_double(): num_list = [1, 2, 3, 4] obs = mean(num_list) exp = 2.5 assert obs == exp
def test_zero(): num_list = [3, 0, 5, 4] obs = 3 exp = mean(num_list) assert obs == exp
def test_mean_12345(): num_list=[1,2,3,4,5] calc_mean=mean(num_list) expected_mean=3 assert expected_mean == calc_mean