I am puzzled about the mean function in NumPy.
I illustrate with example.
first I create a array.
t_a = np.array([
[1,2,3,4],
[5,6,7,8],
[9,10,11,12],
[13,14,15,16]])
I understand to get mean for each row or column by using axis=0 or axis=1.
print(np.mean(t_a, axis=0))
result: 7 8 9 10
print(np.mean(t_a, axis=1))
result: 2.5 6.5 10.5 14.5
The problem is if I want mean value for only one of the rows.
I manage to get result for one column by doing:
print(np.mean(t_a[:,2], axis=0))
result: 9
However if I try to apply that on a row it do not work.
I expexted the line below to result in 10.5 but I get a error.
print(np.mean(t_a[:2,:], axis=1))
How come column example works but row example does not, I do not understand the logical difference.
Thank you.
Best regards,
Christer Eriksson