import numpy as np
import tensorly as tl
X = tl.tensor(np.arange(24).reshape(3, 4, 2))
reshape将np创建的数组变换维度,返回的是一个3*4*2的三维张量
print(X[:, :, 0])
print(X[:, :, 1])
print(tl.unfold(X, mode=0))
print(tl.unfold(X, mode=1))
print(tl.unfold(X, mode=2))
unfolding = tl.unfold(X, 1)
original_shape = X.shape
tl.fold(unfolding, mode=1, shape=original_sha
M = tl.tensor(np.arange(4*5).reshape(5, 4))
print(M.shape)
res = tl.tenalg.mode_dot(X, M, mode=1)
转载自
https://github.com/hustfc/tensorlynotebooks/blob/master/01_tensor_basics/tensor_manipulation.ipynb