candle_core

Module npy

Source
Expand description

Numpy support for tensors.

The spec for the npy format can be found in npy-format. The functions from this module can be used to read tensors from npy/npz files or write tensors to these files. A npy file contains a single tensor (unnamed) whereas a npz file can contain multiple named tensors. npz files are also compressed.

These two formats are easy to use in Python using the numpy library.

import numpy as np
x = np.arange(10)

# Write a npy file.
np.save("test.npy", x)

# Read a value from the npy file.
x = np.load("test.npy")

# Write multiple values to a npz file.
values = { "x": x, "x_plus_one": x + 1 }
np.savez("test.npz", **values)

# Load multiple values from a npz file.
values = np.loadz("test.npz")

Structsยง