← Back to NumPy Course | Chapter 12: Advanced Topics | Lesson 3 of 7

Strides

Strides tell NumPy how many bytes to jump to move to the next element along each axis.

In this page:

  1. Strides
Syntax
python
arr.strides

Strides

Strides are how NumPy maps a multi-dimensional index onto flat memory. A C-ordered (3, 4) int64 array has strides (32, 8). Transposing just swaps strides without moving data, which is why it is instant.

Note: np.lib.stride_tricks.as_strided can build sliding windows but can read invalid memory if misused.

Example: Strides

python
import numpy as np

a = np.arange(12, dtype=np.int64).reshape(3, 4)
print(a.strides)
print(a.T.strides)
print(a.T.flags["C_CONTIGUOUS"])

# Output:
# (32, 8)
# (8, 32)
# False
Related Topics
Common Mistakes
  1. Confusing strides in bytes with element counts
  2. Using as_strided without care
  3. Assuming a transpose copies data
Chapter Summary
  • strides are byte steps per axis
  • Transpose swaps strides
  • No data is moved
  • as_strided is powerful but risky
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.