What is axis in NumPy operations?

Updated May 17, 2026

Short answer

Axis defines the dimension along which operations are performed.

Deep explanation

Axis 0 refers to rows and axis 1 refers to columns in 2D arrays. It controls reduction behavior in aggregation functions.

Real-world example

Computing column-wise averages in datasets.

Common mistakes

  • Confusing axis direction in multidimensional arrays.

Follow-up questions

  • What does axis=-1 mean?
  • How does axis affect reshape?

More NumPy interview questions

View all →