Tensor¶
- class tract.tensor.Tensor(ptr)[source]¶
A multidimensional array of typed data, the fundamental data carrier in tract.
Tensors flow in and out of models: they are the inputs you feed to
Runnable.run()and the outputs you get back. On the Python side, convert to and from numpy arrays withto_numpy()andfrom_numpy().- from_numpy() Tensor[source]¶
Builds a tensor from a numpy array, preserving its rank.
numpy.ascontiguousarray promotes 0-d arrays to rank 1, so the original rank is restored afterwards: a scalar input must stay a scalar to match a rank-0 fact.
- into_numpy() array[source]¶
Same as to_numpy(), but drop the tensor content once the numpy array is built.
- load_npy() Tensor[source]¶
Read a tensor from a numpy
.npyfile.Unstable: needs libtract built with the
unstable-npyzfeature.
- load_npy_buffer() Tensor[source]¶
Read a tensor from the content of a numpy
.npyfile.Unstable: needs libtract built with the
unstable-npyzfeature.