really? Because in my Colab notebook, I have this code:
import numpy as np
list = [0, 1, 2, 3, 4, 5, 6, 7, 8]
def average(arr): #finalized
vertavg0 = np.mean(arr[: , 0 ])
vertavg1 = np.mean(arr[: , 1 ])
vertavg2 = np.mean(arr[: , 2 ])
vertavg = [vertavg0, vertavg1, vertavg2]
print(vertavg)
print(np.mean(arr, axis=0)) # ****This print Statement*****
horavg0 = np.mean(arr[0, :])
horavg1 = np.mean(arr[1, :])
horavg2 = np.mean(arr[2, :])
horavg = [horavg0, horavg1, horavg2]
linavg = np.mean(arr)
return [vertavg, horavg, linavg]
def variance(arr): #finalized
vertvar0 = np.var(arr[:, 0])
vertvar1 = np.var(arr[:, 1])
vertvar2 = np.var(arr[:, 2])
vertvar = [vertvar0, vertvar1, vertvar2]
horvar0 = np.var(arr[0, :])
horvar1 = np.var(arr[1, :])
horvar2 = np.var(arr[2, :])
horvar = [horvar0, horvar1, horvar2]
linvar = np.var(arr)
return [vertvar, horvar, linvar]
def std(arr): #finalized
vertstd = [np.std(arr[:, 0]), np.std(arr[:, 1]), np.std(arr[:, 2])]
horstd = [np.std(arr[0, :]), np.std(arr[1, :]), np.std(arr[2, :])]
linstd = np.std(arr)
return [vertstd, horstd, linstd]
def calculate(list):
if len(list) < 9:
raise ValueError("List must contain nine numbers.")
top = np.asarray(list[:3])
middle = np.asarray(list [3:6])
bottom = np.asarray(list [6: 9])
final = np.append([top],[middle],axis=0)
final = np.append(final, [bottom], axis = 0)
print(final)
average(final)
variance(final)
std(final)
calculate(list)
And the print statement prints out this result:
[3. 4. 5.]