扫描Theano中张量变量的每个其他元素

时间:2015-12-09 11:24:34

标签: numpy parallel-processing gpgpu theano

它应该产生类似的东西:

input = [1,2,3,4,5,6]
output = scan_every_other(lambda x:x, input)
// output should be [1,3,5]

我已经简要地阅读了theano.scan tutorial,但我没有找到我正在寻找的东西。 谢谢。:)

1 个答案:

答案 0 :(得分:1)

您不需要使用theano.scan。只需使用普通的索引/切片表示法,如numpy:

numpy,如果

input = [1,2,3,4,5,6]

然后

print input[::2]

将显示

[1, 3, 5]

在Theano中,这可以通过做同样的事情来实现:

import theano
import theano.tensor as tt
input = tt.vector()
f = theano.function([input], input[::2])
print f([1,2,3,4,5,6])