cerremony
cerremony

Reputation: 223

Slicing and indexing in Theano

I want to index a Tensor Variable in Theano as such:

I want to get [[1,2],[4,5],[7,8]], and [[2,3],[5,6],[8,9]].

For a numpy varaible I would simply do x[:,0:-1] and x[:,1:x.shape[0]], respectively, but I can't figure out how to get the results I want in Theano.

Upvotes: 2

Views: 1666

Answers (1)

uyaseen
uyaseen

Reputation: 1201

You would do it the same way in Theano as you are doing in 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_))

Upvotes: 4

Related Questions