axis=0 and axis=1 Feel BackwardsYou've probably seen:
np.mean(X, axis=0)
and wondered:
"Why does axis 0 mean columns?"
Think about what NumPy is doing.
📌
axis=0 means:Collapse the rows.
So you move down each column and get one value per column.
📌
axis=1 means:Collapse the columns.
So you move across each row and get one value per row.
For:
1 2 3
4 5 6
np.mean(X, axis=0)
gives:
[2.5, 3.5, 4.5]
On the other hand:
np.mean(X, axis=1)
gives:
[2, 5]
Don't memorize the numbers.
Just Remember: The axis you specify is the dimension that gets collapsed.
#NumPy
