TuckerTensorTrain.save#
- t3toolbox.tucker_tensor_train.TuckerTensorTrain.save(file)#
def save( self, file, ) -> None:
Save a Tucker tensor train to a file.
- Parameters:
file (str or file) – Either the filename (string) or an open file (file-like object) where the data will be saved. If file is a string or a Path, the
.npzextension will be appended to the filename if it is not already there.- Raises:
ValueError – If the Tucker tensor train is inconsistent
RuntimeError – If the Tucker tensor train fails to save.
- Return type:
None
See also
Examples
>>> import numpy as np >>> import t3toolbox.tucker_tensor_train as t3 >>> x = t3.TuckerTensorTrain.randn((14,15,16), (4,5,6), (1,3,2,1)) >>> fname = 't3_file.npz' >>> x.save(fname) # Save to file 't3_file.npz' >>> x2 = t3.TuckerTensorTrain.load(fname) # Load from file >>> tucker_cores, tt_cores = x.data >>> tucker_cores2, tt_cores2 = x2.data >>> print([float(np.linalg.norm(B - B2)) for B, B2 in zip(tucker_cores, tucker_cores2)]) [0.0, 0.0, 0.0] >>> print([float(np.linalg.norm(G - G2)) for G, G2 in zip(tt_cores, tt_cores2)]) [0.0, 0.0, 0.0]