tensorstore.TensorStore.__array__(self, dtype: numpy.dtype | None = None, copy: bool | None = None, context: object | None = None) ArrayLike

Automatic conversion to numpy.ndarray for interoperability with NumPy.

Synchronously reads from the current domain and returns the result as an array. Equivalent to self.read().result().

Examples

>>> dataset = await ts.open(
...     {
...         'driver': 'zarr',
...         'kvstore': {
...             'driver': 'memory'
...         }
...     },
...     dtype=ts.uint32,
...     shape=[70, 80],
...     create=True)
>>> dataset[10:20, 5:10] + np.array(5, dtype=np.uint32)
array([[5, 5, 5, 5, 5],
       [5, 5, 5, 5, 5],
       [5, 5, 5, 5, 5],
       [5, 5, 5, 5, 5],
       [5, 5, 5, 5, 5],
       [5, 5, 5, 5, 5],
       [5, 5, 5, 5, 5],
       [5, 5, 5, 5, 5],
       [5, 5, 5, 5, 5],
       [5, 5, 5, 5, 5]], dtype=uint32)

Warning

This reads the entire domain into memory and blocks the current thread while reading. For large arrays, it may be better to partition the domain into blocks and process each block separately.

See also