Memoryview Attributes
memoryview.shape
Read the lengths of the logical dimensions as a tuple. A flat view of six elements has shape (6,); a two-by-three layout has shape (2, 3). A zero-dimensional view has an empty tuple, representing a scalar rather than zero elements. The product of the dimensions gives the element count, taking an empty product as one. Shape is not a byte count; multiply by itemsize for nbytes. Read-only attribute.
Formal Syntax & Structure
python syntaxpython
view.shapeReturn Value
tuple[int, ...]
Length of each logical dimension.
Working Example
Example Snippetpython
flat = memoryview(b"ABCDEF")print(flat.shape)print(flat.cast("B", [2, 3]).shape)print(flat[::2].shape)