Tell us what’s happening:
Hi,
I am very new to freecodecamp and have begun with Data Analysis course. I have looked up in the forum and based on which I have re-written then below code. Each time I run the program there is this error that comes up saying mean is local variable referenced before assignment? Obviously; I can’t submit my Project before this error is resolved. Please assist.
Your code so far
import numpy as np
def calculate(list):
if len(list) < 9 or len(list) > 9:
print("List must contain only 9 numbers altogether ")
else:
arraylist = np.array(list)
arraylist = arraylist.reshape(3,3)
mean = [(np.mean(arraylist, axis=0).tolist(), np.mean(arraylist, axis =1).tolist(), np.mean(arraylist))]
var = [(np.var(arraylist, axis=0).tolist(), np.var(arraylist, axis =1).tolist(), np.var(arraylist))]
stddev = [(np.std(arraylist, axis=0).tolist(), np.std(arraylist, axis =1).tolist(), np.std(arraylist))]
maxval = [(np.max(arraylist, axis=0).tolist(), np.max(arraylist, axis =1).tolist(), np.max(arraylist))]
minval = [(np.min(arraylist, axis=0).tolist(), np.min(arraylist, axis =1).tolist(), np.min(arraylist))]
sumval = [(np.sum(arraylist, axis=0).tolist(), np.sum(arraylist, axis =1).tolist(), np.sum(arraylist))]
calculations = { 'Mean': mean,
'Variance': var,
'Standard Deviation': stddev,
'Max': maxval,
'Min': minval,
'Sum': sumval
}
return calculations
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36
.
Challenge: Mean-Variance-Standard Deviation Calculator
Link to the challenge: