liveBook · Manning

Stride

As explained in Fast Python: High performance techniques for large datasets

A stride is the step interval between successive positions or elements accessed, selected, or processed along a dimension or sequence.

A NumPy stride is the number of bytes to step along a dimension to reach the next element. Together, shape and strides describe how an array view presents data in memory. section 4.4 section 4.1.2

Reading stride values

A one-dimensional array of 4-byte integers has a stride of 4. Reshaping the same data into a 2 × 5 matrix gives it a stride for each dimension; transposing the matrix changes those values while preserving shared memory. section 4.1.2

Stride changes can describe different views of existing array data:

  • Reverse an array or image dimension by using a negative stride. section 4.1.3
  • Use slicing, transposition, or rotation to present array data differently without copying it in the demonstrated cases. section 4.1.3
  • Treat numpy.lib.stride_tricks.as_strided with extreme care because arbitrary shape and stride values can be wrong. section 4.1.3

How Fast Python: High performance techniques for large datasets covers it

How deep it goes
Defines strides as byte steps and demonstrates them with reshaping, transposition, slicing, and image views.
Examples
Demonstrates reshaped and transposed arrays, reversed dimensions, and flipped, rotated, or sliced images.
What it assumes
Builds from array shape and element size, introducing stride behavior through one- and two-dimensional arrays.
What you can do after
Understand how shape and strides describe NumPy views over existing array data.
How it connects
Connects strides to NumPy array views, shape, slicing, and transposition.

Also explained in

Compare how 8 books explain stride →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Fast Python: High performance techniques for large datasets. The section links point to the parts of the book it draws on.