第一步:安装Tensorly?
可移步到该篇博客中:Anaconda 安装 tensorly_小木王子、的博客-CSDN博客
第二步:借助tensor.decomposition模块进行分解
import numpy as np
tensor = np.random.random([10,10,10])
from tensorly.decomposition import matrix_product_state
factors = matrix_product_state(state,[1,2,3,1])
len(factors)→2
[f.shape for f in factors] → [(1,10,2),(2,10,3),(3,10,1)]