Mean_var_std calculator

Traceback (most recent call last):
File “/home/runner/boilerplate-mean-variance-standard-deviation-calculator-2/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 937, in assertAlmostEqual
if first == second:
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

======================================================================
ERROR: test_calculate2 (test_module.UnitTests)

Traceback (most recent call last):
File “/home/runner/boilerplate-mean-variance-standard-deviation-calculator-2/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 937, in assertAlmostEqual
if first == second:
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
ths is the error which i am unable to solve

Your code so far
def calculate(list):
if(len(list) != 9):
raise ValueError(“List must contain nine numbers.”)

lst = np.array(list).reshape(3,3)
print(lst)
calculations = {
‘mean’: [lst.mean(axis = 0), lst.mean(axis = 1), lst.mean()],
‘variance’: [lst.var(axis = 0), lst.var(axis = 1), lst.var()],
‘standard deviation’: [lst.std(axis = 0), lst.std(axis = 1), lst.std()],
‘max’: [lst.max(axis = 0), lst.max(axis = 1), lst.max()],
‘min’: [lst.min(axis = 0), lst.min(axis = 1), lst.min()],
‘sum’: [lst.sum(axis = 0), lst.sum(axis = 1), lst.sum()]

}

return calculations

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.212 Safari/537.36.

Challenge: Mean-Variance-Standard Deviation Calculator

Link to the challenge:

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