Provides one-dimensional tightly packed view on a memory range. Convertible
both from and to Python objects supporting the Buffer Protocol, with one
dimension and stride of
1. See StridedArrayView1D and others for
more generic views. ArrayView is immutable, see MutableArrayView for
the mutable alterantive. All slicing operations are supported, specifying a
non-trivial stride will return StridedArrayView1D instead of ArrayView.
>>> a = b'hello' >>> b = containers.ArrayView(a) >>> b 'l' >>> bytes(b[1:4]) b'ell'
Unlike in C++, the view keeps a reference to the original memory owner
object in the owner field, meaning that calling
del on the original
object will not invalidate the view. Slicing a view creates a new view
referencing the same original object, without any dependency on the
previous view. That means a long chained slicing operation will not cause
increased memory usage.
>>> b.owner is a True >>> b[1:4][:-1].owner is a True
The owner is
None if the view is empty.
The ArrayView class is equivalent to one-dimensional memoryview with a
1. For multiple dimensions and non-trivial strides,
StridedArrayView1D and friends provide a superset of memoryview
- def __bytes__(self, /) -> bytes
- Convert to bytes
- def __getitem__(self, arg0: int, /) -> str
- Value at given position
- def __getitem__(self, arg0: slice, /) -> object
- Slice the view
- def __init__(self, /) -> None
- Default constructor
- def __init__(self, arg0: buffer, /) -> None
- Construct from a buffer
- def __len__(self, /) -> int
- View size