扫描 Theano 中张量变量的所有其他元素
Scan over every other element of a tensor variable in 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 但我没有找到我要找的东西。
谢谢。:)
您不需要使用 theano.scan
。只需使用普通的 index/slice 表示法,如 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])
它应该产生如下内容:
input = [1,2,3,4,5,6]
output = scan_every_other(lambda x:x, input)
// output should be [1,3,5]
我已经简要阅读了 theano.scan tutorial 但我没有找到我要找的东西。 谢谢。:)
您不需要使用 theano.scan
。只需使用普通的 index/slice 表示法,如 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])