Hi there! My english is not very good, but I’ll try to explain my self the best possible. I’m having problems with the ‘Exception’ of the project, when the list has just a few numbers (<9). I’d already try with a lot of alternatives and modifications, but I’ve not see which is(are) the detail(s) that are making mistakes in it.
Please help me! Greetings from Chile!
import numpy as np
def calculate(list):
try:
if len(list)==9:
a=np.array(list)
b=a.reshape(3,3)
m1=np.mean(b,axis=0).tolist()
m2=np.mean(b,axis=1).tolist()
m3=np.mean(b).tolist()
mean=[m1,m2,m3]
v1=np.var(b,axis=0).tolist()
v2=np.var(b,axis=1).tolist()
v3=np.var(b).tolist()
variance=[v1,v2,v3]
s1=np.std(b,axis=0).tolist()
s2=np.std(b,axis=1).tolist()
s3=np.std(b).tolist()
std=[s1,s2,s3]
ma1=np.max(b,axis=0).tolist()
ma2=np.max(b,axis=1).tolist()
ma3=np.max(b).tolist()
ma=[ma1,ma2,ma3]
mi1=np.min(b,axis=0).tolist()
mi2=np.min(b,axis=1).tolist()
mi3=np.min(b).tolist()
mi=[mi1,mi2,mi3]
su1=np.sum(b,axis=0).tolist()
su2=np.sum(b,axis=1).tolist()
su3=np.sum(b).tolist()
su=[su1,su2,su3]
calculations={'mean':mean, 'variance':variance, 'standard deviation':std, 'max':ma, 'min':mi, 'sum':su}
except ValueError:
print('List must contain nine numbers.')
return calculations
Your code so far
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Safari/537.36
.
Challenge: Mean-Variance-Standard Deviation Calculator
Link to the challenge: