When I run, it shown:
TypeError: unsupported operand type(s) for -: ‘dict’ and ‘dict’
May I ask why? And how to fix it?
Your code so far
import numpy as np
def calculate(list):
if len(list) < 9:
raise ValueError ("List must contain nine numbers.")
else:
data=np.array(list).reshape(3,3)
meanaxis1=np.mean(data,axis=0).tolist()
meanaxis2=np.mean(data,axis=1).tolist()
meanflattened=np.mean(data).tolist()
varaxis1=np.var(data,axis=0).tolist()
varaxis2=np.var(data,axis=1).tolist()
varflattened=np.var(data).flatten().tolist()
stdaxis1=np.std(data,axis=0).tolist()
stdaxis2=np.std(data,axis=1).tolist()
stdflattened=np.std(data).flatten().tolist()
maxaxis1=np.max(data,axis=0).tolist()
maxaxis2=np.max(data,axis=1).tolist()
maxflattened=np.max(data).flatten().tolist()
minaxis1=np.min(data,axis=0).tolist()
minaxis2=np.min(data,axis=1).tolist()
minflattened=np.min(data).flatten().tolist()
sumaxis1=np.sum(data,axis=0).tolist()
sumaxis2=np.sum(data,axis=1).tolist()
sumflattened=np.sum(data).flatten().tolist()
calculations={
'mean': [meanaxis1, meanaxis2, meanflattened],
'variance': [varaxis1, varaxis2, varflattened],
'standard deviation': [stdaxis1, stdaxis2, stdflattened],
'max': [maxaxis1, maxaxis2, maxflattened],
'min': [minaxis1, minaxis2, minflattened],
'sum': [sumaxis1, sumaxis2, sumflattened]
}
return calculations
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36
Challenge Information:
Data Analysis with Python Projects - Mean-Variance-Standard Deviation Calculator