tensorstore.TensorStore.__setitem__(self, indices: NumpyIndexingSpec, source: TensorStore | ArrayLike) None

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

This allows Python subscript assignment syntax to be used as a shorthand for self[indices].write(source).result().

Example

>>> dataset = ts.open({
...     'driver': 'zarr',
...     'kvstore': {
...         'driver': 'memory'
...     }
... },
...                   dtype=ts.uint32,
...                   shape=[70, 80],
...                   create=True).result()
>>> dataset[5:10, 6:8] = [1, 2]
>>> dataset[4:10, 5:9].read().result()
array([[0, 0, 0, 0],
       [0, 1, 2, 0],
       [0, 1, 2, 0],
       [0, 1, 2, 0],
       [0, 1, 2, 0],
       [0, 1, 2, 0]], dtype=uint32)
Parameters:
indices: NumpyIndexingSpec

NumPy-style indexing terms.

source: TensorStore | ArrayLike

Source array, broadcast-compatible with self[indices].domain and with a data type convertible to self.dtype. May be an existing TensorStore or any ArrayLike, including a scalar.

Transactional writes are also supported:

>>> txn = ts.Transaction()
>>> dataset = ts.open({
...     'driver': 'zarr',
...     'kvstore': {
...         'driver': 'memory'
...     }
... },
...                   dtype=ts.uint32,
...                   shape=[70, 80],
...                   create=True).result()
>>> dataset.with_transaction(txn)[5:10, 6:8] = [1, 2]
>>> txn.commit_sync()

Warning

When not using a transaction, the subscript assignment syntax always blocks synchronously on the completion of the write operation. When performing multiple, fine-grained writes, it is recommended to either use a transaction or use the asynchronous TensorStore.write interface directly.