Tell us what’s happening:
Describe your issue in detail here.
I need to create a function that outputs as the following:
{
'mean': [[3.0, 4.0, 5.0], [1.0, 4.0, 7.0], 4.0],
'variance': [[6.0, 6.0, 6.0], [0.6666666666666666, 0.6666666666666666, 0.6666666666666666], 6.666666666666667],
'standard deviation': [[2.449489742783178, 2.449489742783178, 2.449489742783178], [0.816496580927726, 0.816496580927726, 0.816496580927726], 2.581988897471611],
'max': [[6, 7, 8], [2, 5, 8], 8],
'min': [[0, 1, 2], [0, 3, 6], 0],
'sum': [[9, 12, 15], [3, 12, 21], 36]
}
I don't know how to get the function to print out the other axis and the flattened axis, so that my function is identical to the answer.
My code
import numpy as np
def calculate(list):
a = np.arange(9).reshape(3, 3)
b = np.mean(a.copy(), axis=(0))
print(b)
c = np.var(a.copy(), axis=(0))
print(c)
d = np.std(a.copy(), axis=(0))
print(d)
e = np.max(a.copy(), axis=(0))
print(e)
f = np.min(a.copy(), axis=(0))
print(f)
g = np.sum(a.copy(), axis=(0))
print(g)
return calculations
my output
[3. 4. 5.]
[6. 6. 6.]
[2.44948974 2.44948974 2.44948974]
[6 7 8]
[0 1 2]
[ 9 12 15]]
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/99.0.4844.74 Safari/537.36
Challenge: Mean-Variance-Standard Deviation Calculator
Link to the challenge: