blosc2.frombuffer#
- blosc2.frombuffer(buffer: bytes, shape: int | tuple | list, dtype: ~numpy.dtype | str = <class 'numpy.uint8'>, **kwargs: ~typing.Any) NDArray #
Create an array out of a buffer.
- Parameters:
buffer¶ (bytes) – The buffer of the data to populate the container.
shape¶ (int, tuple or list) – The shape for the final container.
dtype¶ (np.dtype or list str) – The ndarray dtype in NumPy format. Default is np.uint8. This will override the typesize in the cparams if they are passed.
kwargs¶ (dict, optional) – Keyword arguments that are supported by the
empty()
constructor.
- Returns:
out – A NDArray is returned.
- Return type:
Examples
>>> import blosc2 >>> import numpy as np >>> shape = [25, 10] >>> chunks = (49, 49) >>> dtype = np.dtype("|S8") >>> typesize = dtype.itemsize >>> # Create a buffer >>> buffer = bytes(np.random.normal(0, 1, np.prod(shape)) * typesize) >>> # Create a NDArray from a buffer with default blocks >>> a = blosc2.frombuffer(buffer, shape, chunks=chunks, dtype=dtype)