blosc2.load_tensor#
- blosc2.load_tensor(urlpath: str, dparams: dict | None = None) tensorflow.Tensor | torch.Tensor | np.ndarray #
Load a serialized PyTorch or TensorFlow tensor or NumPy array from a file.
- Parameters:
urlpath¶ (str) – The path to the file where the tensor or array is stored.
dparams¶ (dict, optional) – A dictionary with the decompression parameters, which are the same as those used in the
decompress2()
function.
- Returns:
out – The unpacked PyTorch or TensorFlow tensor or NumPy array.
- Return type:
tensor or ndarray
- Raises:
TypeError – If
urlpath
is not in cframe formatRunTimeError – If some other problem is detected.
Examples
>>> import numpy as np >>> th = np.arange(1e6, dtype=np.float32) >>> size = blosc2.save_tensor(th, "test.bl2", mode="w") >>> if not os.getenv("BTUNE_TRADEOFF"): ... assert size < th.size * th.itemsize ... >>> th2 = blosc2.load_tensor("test.bl2") >>> np.array_equal(th, th2) True
See also