2016-10-28 2 views
1

Ich möchte ein Tensor Variable in Theano als solche zu indizieren:Slicing und Indizierung in Theano

  • x hat Typ theano.tensor.var.TensorVariable (zB [[1,2,3],[4,5,6],[7,8,9]])

Ich will bekommen [[1,2],[4,5],[7,8]] und [[2,3],[5,6],[8,9]].

Für ein numpy varaible würde ich einfach x[:,0:-1] bzw. x[:,1:x.shape[0]] tun, aber ich kann nicht herausfinden, wie man die Ergebnisse erhält, die ich in Theano will.

Antwort

2

Sie würden es die gleiche Art und Weise in Theano tun, wie Sie in numpy tun:

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