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
Your code so far
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
Your browser information:
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
Link to the challenge: