2016-10-28 2 views
1
でインデックス

私のようなTheanoにおけるテンソル変数インデックスを作成する:スライスとTheano

  • xは、私が取得したいtheano.tensor.var.TensorVariable(例えば[[1,2,3],[4,5,6],[7,8,9]]

を入力しています[[1,2],[4,5],[7,8]]および[[2,3],[5,6],[8,9]]である。

私は単純にx[:,0:-1]x[:,1:x.shape[0]]を実行しますが、私はTheanoで必要な結果を得る方法を理解できません。あなたがnumpyの中でやっているよう

答えて

2

あなたはそれをTheanoで同じようにするだろう:

import theano 
import theano.tensor as T 

x = T.imatrix('x') 
y = x[:, 0: -1] 
z = x[:, 1: x.shape[0]] 

f = theano.function([x], y) 
g = theano.function([x], z) 

x_ = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] 
print(f(x_)) 
print(g(x_))