Memoryview Attributes

memoryview.strides

Read the byte displacement between neighboring logical positions along each dimension. A dense two-by-three unsigned-byte layout has strides (3, 1); stepping through every second byte yields stride (2,), and reversing produces a negative stride. Strides are measured in bytes, not elements, and can be zero or negative for some exporters. The tuple is empty for a scalar view. Do not use this attribute as an unchecked address calculation or assume contiguity.

Formal Syntax & Structure

python syntaxpython
view.strides

Return Value

tuple[int, ...]

Byte displacement for each dimension.

Working Example

Example Snippetpython
flat = memoryview(b"ABCDEF")print(flat.cast("B", [2, 3]).strides)print(flat[::2].strides)print(flat[::-1].strides)
Python Reference