Strides
Strides tell NumPy how many bytes to jump to move to the next element along each axis.
In this page:
Syntax
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
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
- Confusing strides in bytes with element counts
- Using as_strided without care
- 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: