blosc2.NDArray.get_chunk#

NDArray.get_chunk(nchunk: int) bytes#

Shortcut to SChunk.get_chunk. This can be accessed through the schunk attribute as well.

Parameters:

nchunk (int) – The index of the chunk to retrieve.

Returns:

chunk – The chunk data at the specified index.

Return type:

bytes

See also

schunk

The attribute that provides access to the underlying SChunk object.

Examples

>>> import blosc2
>>> import numpy as np
>>> # Create an SChunk with some data
>>> array = np.arange(10)
>>> ndarray = blosc2.asarray(array)
>>> chunk = ndarray.get_chunk(0)
>>> # Decompress the chunk to convert it into a numpy array
>>> decompressed_chunk = blosc2.decompress(chunk)
>>> np_array_chunk = np.frombuffer(decompressed_chunk, dtype=np.int64)
>>> # Verify the content of the chunk
>>> if isinstance(np_array_chunk, np.ndarray):
>>>         print(np_array_chunk)
>>>         print(np_array_chunk.shape) # Assuming chunk is a list or numpy array
[ 0  1  2  3  4  5  6  7  8  9]
(10,)