blosc2.NDArray.slice#

NDArray.slice(key: int | slice | Sequence[slice], **kwargs: Any) NDArray#

Get a (multidimensional) slice as a new NDArray.

Parameters:
  • key (int, slice or sequence of slices) – The index for the slices to be retrieved. Note that the step parameter is not yet supported in slices.

  • kwargs (dict, optional) – Additional keyword arguments supported by the empty() constructor.

Returns:

out – An array containing the requested data. The dtype will match that of self.

Return type:

NDArray

Examples

>>> import blosc2
>>> import numpy as np
>>> shape = [23, 11]
>>> a = np.arange(np.prod(shape)).reshape(shape)
>>> # Create an array
>>> b = blosc2.asarray(a)
>>> slices = (slice(3, 7), slice(1, 11))
>>> # Get a slice as a new NDArray
>>> c = b.slice(slices)
>>> print(c.shape)
(4, 10)
>>> print(type(c))
<class 'blosc2.ndarray.NDArray'>