Help with Mean-Variance... Calculator

Hi, I dont get why my code is not passing the tests.

``````import numpy as np

def calculate(list):
array = np.array(list)
try:
matrix = np.reshape(array, (3, 3))
except ValueError:
raise ValueError("List must contain nine numbers.")

calculations = {
"mean" : [np.mean(matrix, axis=0).tolist(), np.mean(matrix, axis=1).tolist(),  np.mean(matrix).tolist()]  ,
"variance" : [np.var(matrix, axis=0).tolist(), np.var(matrix, axis=1).tolist(), np.var(matrix).tolist()],
"standart deviation" : [np.std(matrix, axis=0).tolist(), np.std(matrix, axis=1).tolist(), np.std(matrix).tolist()],
"max" : [ np.amax(matrix, axis=0).tolist(), np.amax(matrix, axis=1).tolist(), np.amax(matrix).tolist()],
"min" : [np.amin(matrix, axis=0).tolist(), np.amin(matrix, axis=1).tolist(), np.amin(matrix).tolist()],
"sum" : [np.sum(matrix, axis=0).tolist(), np.sum(matrix, axis=1).tolist(), np.sum(matrix).tolist()]
}

return calculations
``````
``````python main.py
{'mean': [[3.0, 4.0, 5.0], [1.0, 4.0, 7.0], 4.0], 'variance': [[6.0, 6.0, 6.0], [0.6666666666666666, 0.6666666666666666, 0.6666666666666666], 6.666666666666667], 'standart deviation': [[2.449489742783178, 2.449489742783178, 2.449489742783178], [0.816496580927726, 0.816496580927726, 0.816496580927726], 2.581988897471611], 'max': [[6, 7, 8], [2, 5, 8], 8], 'min': [[0, 1, 2], [0, 3, 6], 0], 'sum': [[9, 12, 15], [3, 12, 21], 36]}
EE.
======================================================================
ERROR: test_calculate (test_module.UnitTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/runner/boilerplate-mean-variance-standard-deviation-calculator/test_module.py", line 10, in test_calculate
self.assertAlmostEqual(actual, expected, "Expected different output when calling 'calculate()' with '[2,6,2,8,4,0,1,5,7]'")
File "/usr/lib/python3.8/unittest/case.py", line 943, in assertAlmostEqual
diff = abs(first - second)
TypeError: unsupported operand type(s) for -: 'dict' and 'dict'

======================================================================
ERROR: test_calculate2 (test_module.UnitTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/runner/boilerplate-mean-variance-standard-deviation-calculator/test_module.py", line 15, in test_calculate2
self.assertAlmostEqual(actual, expected, "Expected different output when calling 'calculate()' with '[9,1,5,3,3,3,2,9,0]'")
File "/usr/lib/python3.8/unittest/case.py", line 943, in assertAlmostEqual
diff = abs(first - second)
TypeError: unsupported operand type(s) for -: 'dict' and 'dict'

----------------------------------------------------------------------
Ran 3 tests in 0.021s

FAILED (errors=2)

``````

Thank you for the help.

It’s `standard deviation` not `standart deviation` - first word ending with a “d”

Thank you! I would have searched ages to find this typo.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.