class tensorstore.TensorStore

Asynchronous multi-dimensional array handle.

Examples

>>> dataset = await ts.open(
...     {
...         'driver': 'zarr',
...         'kvstore': {
...             'driver': 'memory'
...         },
...     },
...     dtype=ts.uint32,
...     shape=[1000, 20000],
...     create=True)
>>> dataset
TensorStore({
  'context': {
    'cache_pool': {},
    'data_copy_concurrency': {},
    'memory_key_value_store': {},
  },
  'driver': 'zarr',
  'dtype': 'uint32',
  'kvstore': {'driver': 'memory'},
  'metadata': {
    'chunks': [1000, 1049],
    'compressor': {
      'blocksize': 0,
      'clevel': 5,
      'cname': 'lz4',
      'id': 'blosc',
      'shuffle': -1,
    },
    'dimension_separator': '.',
    'dtype': '<u4',
    'fill_value': None,
    'filters': None,
    'order': 'C',
    'shape': [1000, 20000],
    'zarr_format': 2,
  },
  'transform': {
    'input_exclusive_max': [[1000], [20000]],
    'input_inclusive_min': [0, 0],
  },
})
>>> await dataset[5:10, 6:8].write(42)
>>> await dataset[0:10, 0:10].read()
array([[ 0,  0,  0,  0,  0,  0,  0,  0,  0,  0],
       [ 0,  0,  0,  0,  0,  0,  0,  0,  0,  0],
       [ 0,  0,  0,  0,  0,  0,  0,  0,  0,  0],
       [ 0,  0,  0,  0,  0,  0,  0,  0,  0,  0],
       [ 0,  0,  0,  0,  0,  0,  0,  0,  0,  0],
       [ 0,  0,  0,  0,  0,  0, 42, 42,  0,  0],
       [ 0,  0,  0,  0,  0,  0, 42, 42,  0,  0],
       [ 0,  0,  0,  0,  0,  0, 42, 42,  0,  0],
       [ 0,  0,  0,  0,  0,  0, 42, 42,  0,  0],
       [ 0,  0,  0,  0,  0,  0, 42, 42,  0,  0]], dtype=uint32)

Accessors

rank : int

Number of dimensions in the domain.

ndim : int

Alias for rank.

domain : IndexDomain

Domain of the array.

spec(*, open: bool | None = None, ...) Spec

Spec that may be used to re-open or re-create the TensorStore.

mode : str

Read/write mode.

readable : bool

Indicates if reading is supported.

writable : bool

Indicates if writing is supported.

chunk_layout : ChunkLayout

Chunk layout of the TensorStore.

codec : CodecSpec | None

Data codec spec.

fill_value : array_like | None

Fill value for positions not yet written.

dimension_units : Tuple[Unit | None, ...]

Physical units of each dimension of the domain.

kvstore : KvStore | None

Associated key-value store used as the underlying storage.

schema : Schema

Schema of this TensorStore.

origin : Tuple[int, ...]

Inclusive lower bound of the domain.

shape : Tuple[int, ...]

Shape of the domain.

size : int

Total number of elements in the domain.

Data type

dtype : dtype

Data type of the array.

astype(dtype: dtype) TensorStore

Returns a read/write view as the specified data type.

I/O

read(order: 'C' | 'F' = 'C') Future[array_like]

Reads the data within the current domain.

write(source: TensorStore | array_like) WriteFutures

Writes to the current domain.

resize(...) Future[TensorStore]

Resizes the current domain, persistently modifying the stored representation.

__array__(dtype: dtype | None = None, ...) array_like

Automatic conversion to numpy.ndarray for interoperability with NumPy.

resolve(fix_resizable_bounds: bool = False) Future[TensorStore]

Obtains updated bounds, subject to the cache policy.

__setitem__(transform: IndexTransform, source)

Synchronously writes using an explicit index transform.

__setitem__(transform: IndexDomain, source: TensorStore | array_like)

Synchronously writes using an explicit index domain.

__setitem__(transform: DimExpression, source)

Synchronously writes using a dimension expression.

__setitem__(indices: NumpyIndexingSpec, source)

Synchronously writes using NumPy-style indexing with default index array semantics.

oindex.__setitem__(indices: NumpyIndexingSpec, source)

Synchronously writes using NumPy-style indexing with outer indexing semantics.

vindex.__setitem__(indices: NumpyIndexingSpec, source)

Synchronously writes using NumPy-style indexing with vectorized indexing semantics.

Transactions

transaction : Transaction | None

Associated transaction used for read/write operations.

with_transaction(transaction: Transaction | None) TensorStore

Returns a transaction-bound view of this TensorStore.

Indexing

__getitem__(transform: IndexTransform) TensorStore

Computes a virtual view using an explicit index transform.

__getitem__(domain: IndexDomain) TensorStore

Computes a virtual view using an explicit index domain.

__getitem__(expr: DimExpression) TensorStore

Computes a virtual view using a dimension expression.

__getitem__(indices: NumpyIndexingSpec) TensorStore

Computes a virtual view using NumPy-style indexing with default index array semantics.

oindex[indices: NumpyIndexingSpec] TensorStore

Computes a virtual view using NumPy-style indexing with outer indexing semantics.

vindex[indices: NumpyIndexingSpec] TensorStore

Computes a virtual view using NumPy-style indexing with vectorized indexing semantics.

T : TensorStore

View with transposed domain (reversed dimension order).