Mean function doubt

If a=np.array([1,2,3,4]) , and I used np.mean(a,axis=1). It is showing error that axis 1 is out of bound .
Please explain why it is showing error.
It can just give minimum of 1st row?

Hello @vatsal50, yes you are right the answer must be the first row, but you need to understand the thing for that.
If we do,

a = np.array([1,2,3,4])
a.shape
# The answer will be (4,) [So if we see the shape is not exactly like we need it to be like (4,1)]
# So, first of all, reshape it,
a = a.reshape(4,1)
# Now you can try on 
np.mean(a,axis= 0)  # 2.5
np.mean(a,axis= 0)  # array([[1],[2],[3],[4]])

I hope it is clear to you. In case if there is some confusion pls let me know.
In case it is clear to you pls mark it as resolve.
Thanks :slight_smile:

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.