# Stumped from Mean-Variance-Standard Deviation

Tell us what’s happening:
This is something that has baffled me for a while. I took a break from this code, because I couldn’t get past the same error. “TypeError: unsupported operand type(s) for -: ‘dict’ and ‘dict’” If anyone can give me a tip with my code, please do so.

EDIT
I should also note, that I have been working on this code on an iPad app, Pythonista. I included all the files used in the REPL

``````import numpy as np

def calculate(list):
if len(list) < 9:
raise ValueError("List must contain nine numbers.")

a = np.array(list).reshape(3,3)

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

return calculations
``````

User Agent is: `Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/13.1 Safari/605.1.15`

Challenge: Mean-Variance-Standard Deviation Calculator

I suspect this is the offending line.

Edit, nope, that line when inserted into my solution.

In fact, all of your code passes on my clone of the project

Never mind it worked.

1 Like

The error appears to be in the unittest module which is part of the test suite “test_module.py”, line 11. “assertAlmostEqual” function doesn’t operate on dictionary types which are being passed to it for evaluation. Facing the same issue. However another mistake in your code is related to the flattened matrix’s statistics. You do not need to convert the output to a list. “a.<>.tolist()” is not required.

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