Python Projects Mean-Variance-Standard Deviation Calculator TypeError

SOLVED:
" 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’"

this is the message I get I can’t figure out what I’ve done wrong or what to change. When I run the function with the test lists in Jupyter notebooks it comes out correct, but when I run it in the repl.it I get the error and the results are different as well. any ideas?

Can you please provide a link to your code?

Thanks.

https://repl.it/@RadTurkin/boilerplate-mean-variance-standard-deviation-calculator-2#mean_var_std.py

The values within the dictionairy are supposed to be lists, but you make tuples.
Replace the round brackets with list-brackets. Also instead of “std” you have to write “standard deviation”.
After changing those, code runs without errors for me.

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

thanks, this worked, solved!

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