tensorlyはテンソルの展開と逆過程を実現する

520 ワード

import tensorly as tl
import numpy as np
a = np.array([[[1,2,3,4],[4,5,6,7],[7,8,9,10]],
            [[11,12,13,14],[20,21,22,23],[15,16,17,18]]])
print(a.shape)
b = tl.unfold(a,mode=0) #  1   
print('b=',b)
c = tl.fold(b,mode=0,shape=(2,3,4)) #           
print('c=',c)

#out

(2, 3, 4)
b= [[ 1  2  3  4  4  5  6  7  7  8  9 10]
 [11 12 13 14 20 21 22 23 15 16 17 18]]
c= [[[ 1  2  3  4]
  [ 4  5  6  7]
  [ 7  8  9 10]]

 [[11 12 13 14]
  [20 21 22 23]
  [15 16 17 18]]]