在theano中,从矢量制作切片矩阵

时间:2015-03-24 04:47:36

标签: python theano

我想在theano的get matrix of vectors from a vector中做同样的事情。

也许,它可以与scan()一起使用。 但我不知道如何在这个问题中应用scan()。

以下是上下文的代码。

import theano
import theano.tensor as T

self.x = T.vector('x')
self.i = T.imatrix('i') 
#indices tuple list. ex)[[0,3],[1,4]] means two slices (from 0 to 3 and from 1 to 4)

self.slices_list = ? #slices from the vector self.x

1 个答案:

答案 0 :(得分:0)

import theano
import theano.tensor as T

self.x = T.vector('x')
self.i = T.imatrix('i') 
#indices tuple list. ex)[[0,3],[1,4]] means two slices (from 0 to 3 and from 1 to 4)

results, updates = theano.scan(lambda v:self.x[v[0]:v[1]], sequences=self.i)
make_slices = theano.function(inputs=[self.x,self.i], outputs=[results])    

self.slices_list = make_slices(x,i)
#'x' and 'i' are theano shared variables
相关问题