-
tensorstore.stack(layers: Sequence[TensorStore | Spec], axis: int =
0
, *, read: bool | None =None
, write: bool | None =None
, context: Context | None =None
, transaction: Transaction | None =None
, rank: int | None =None
, dtype: dtype | None =None
, domain: IndexDomain | None =None
, shape: Sequence[int] | None =None
, dimension_units: Sequence[Unit | str | Real | tuple[Real, str] | None] | None =None
, schema: Schema | None =None
) TensorStore Virtually stacks a sequence of
TensorStore
layers along a new dimension.>>> store = ts.stack([ ... ts.array([1, 2, 3, 4], dtype=ts.uint32), ... ts.array([5, 6, 7, 8], dtype=ts.uint32) ... ]) >>> store TensorStore({ 'context': {'data_copy_concurrency': {}}, 'driver': 'stack', 'dtype': 'uint32', 'layers': [ { 'array': [1, 2, 3, 4], 'driver': 'array', 'dtype': 'uint32', 'transform': { 'input_exclusive_max': [1, 4], 'input_inclusive_min': [0, 0], 'output': [{'input_dimension': 1}], }, }, { 'array': [5, 6, 7, 8], 'driver': 'array', 'dtype': 'uint32', 'transform': { 'input_exclusive_max': [2, 4], 'input_inclusive_min': [1, 0], 'output': [{'input_dimension': 1}], }, }, ], 'schema': {'domain': {'exclusive_max': [2, 4], 'inclusive_min': [0, 0]}}, 'transform': {'input_exclusive_max': [2, 4], 'input_inclusive_min': [0, 0]}, }) >>> await store.read() array([[1, 2, 3, 4], [5, 6, 7, 8]], dtype=uint32) >>> store = ts.stack([ ... ts.array([1, 2, 3, 4], dtype=ts.uint32), ... ts.array([5, 6, 7, 8], dtype=ts.uint32) ... ], ... axis=-1) >>> store TensorStore({ 'context': {'data_copy_concurrency': {}}, 'driver': 'stack', 'dtype': 'uint32', 'layers': [ { 'array': [1, 2, 3, 4], 'driver': 'array', 'dtype': 'uint32', 'transform': { 'input_exclusive_max': [4, 1], 'input_inclusive_min': [0, 0], 'output': [{'input_dimension': 0}], }, }, { 'array': [5, 6, 7, 8], 'driver': 'array', 'dtype': 'uint32', 'transform': { 'input_exclusive_max': [4, 2], 'input_inclusive_min': [0, 1], 'output': [{'input_dimension': 0}], }, }, ], 'schema': {'domain': {'exclusive_max': [4, 2], 'inclusive_min': [0, 0]}}, 'transform': {'input_exclusive_max': [4, 2], 'input_inclusive_min': [0, 0]}, }) >>> await store.read() array([[1, 5], [2, 6], [3, 7], [4, 8]], dtype=uint32)
- Parameters:¶
- layers: Sequence[TensorStore | Spec]¶
Sequence of layers to stack. If a layer is specified as a
Spec
rather than aTensorStore
, it must have a knowndomain
and will be opened on-demand as needed for individual read and write operations.- axis: int =
0
¶ New dimension along which to stack. A negative number counts from the end.
- read: bool | None =
None
¶ Allow read access. Defaults to
True
if neitherread
norwrite
is specified.- write: bool | None =
None
¶ Allow write access. Defaults to
True
if neitherread
norwrite
is specified.- context: Context | None =
None
¶ Shared resource context. Defaults to a new (unshared) context with default options, as returned by
tensorstore.Context()
. To share resources, such as cache pools, between multiple open TensorStores, you must specify a context.- transaction: Transaction | None =
None
¶ Transaction to use for opening/creating, and for subsequent operations. By default, the open is non-transactional.
Note
To perform transactional operations using a
TensorStore
that was previously opened without a transaction, useTensorStore.with_transaction
.- rank: int | None =
None
¶ Constrains the rank of the TensorStore. If there is an index transform, the rank constraint must match the rank of the input space.
- dtype: dtype | None =
None
¶ Constrains the data type of the TensorStore. If a data type has already been set, it is an error to specify a different data type.
- domain: IndexDomain | None =
None
¶ Constrains the domain of the TensorStore. If there is an existing domain, the specified domain is merged with it as follows:
The rank must match the existing rank.
All bounds must match, except that a finite or explicit bound is permitted to match an infinite and implicit bound, and takes precedence.
If both the new and existing domain specify non-empty labels for a dimension, the labels must be equal. If only one of the domains specifies a non-empty label for a dimension, the non-empty label takes precedence.
Note that if there is an index transform, the domain must match the input space, not the output space.
- shape: Sequence[int] | None =
None
¶ Constrains the shape and origin of the TensorStore. Equivalent to specifying a
domain
ofts.IndexDomain(shape=shape)
.Note
This option also constrains the origin of all dimensions to be zero.
- dimension_units: Sequence[Unit | str | Real | tuple[Real, str] | None] | None =
None
¶ Specifies the physical units of each dimension of the domain.
The physical unit for a dimension is the physical quantity corresponding to a single index increment along each dimension.
A value of
None
indicates that the unit is unknown. A dimension-less quantity can be indicated by a unit of""
.- schema: Schema | None =
None
¶ Additional schema constraints to merge with existing constraints.