TGViewer
Data science/ML/AI Data science/ML/AI @datascience_bds · 14K subscribers
Post #1368 377
🧮 NumPy: Why axis=0 and axis=1 Feel Backwards

You'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
  • ❤ 3
More from @datascience_bds
  1. Oct 8, 2026document post
  2. Oct 6, 2026document post
  3. Oct 5, 2026📊 Pandas Cheatsheet Every Data Analyst Should Save Pandas is one of the most important to…
  4. Oct 4, 2026SQLBolt: Interactive SQL You can learn SQL by writing real queries directly in the browser…
  5. Oct 3, 2026Tools vs MCP vs Skills: 3 Layers That Power Production AI Agents
  6. Oct 2, 2026LLM inference speed with vs. without KV caching
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →