2016-10-28 41 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]]

对于一个numpy变化我会简单地做x[:,0:-1]x[:,1:x.shape[0]],但我不知道如何得到我想要的结果在Theano。

回答

2

你会做它Theano相同的方式,你在做numpy的:

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_))