有谁知道如何将 theano 中的张量变量(包含向量)组合到引用原始变量的另一个变量中,类似于 itertools.chain?
现在我无法得到 z = T.concatenate([x,y])
结果 z.shape[0] = shape x.shape[0] + y 的结果.形状[0]。它最终总是以与 x 具有相同形状的 z 结束。
非常感谢您提供的任何帮助。
最佳答案
这是theano.tensor.concatenate
的演示。您可以使用 axis
参数来调整连接哪个维度。
import theano
import theano.tensor as tt
x, y = tt.matrices('x', 'y')
z1 = tt.concatenate([x, y])
z2 = tt.concatenate([x, y], axis=0)
z3 = tt.concatenate([x, y], axis=1)
f = theano.function([x, y], [z1, z2, z3])
for output in f([[1, 2], [3, 4]], [[5, 6], [7, 8]]):
print output.shape
这会打印
(4L, 2L)
(4L, 2L)
(2L, 4L)
所以我无法重现所述行为。使用 z = tt.concatenate([x, y]) 生成一个具有 z.shape[0] = x.shape[0] + y.shape[0]< 的张量
根据需要。
关于python - 有什么方法可以组合类似于 itertools.chain 的 Theano 张量向量吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34149313/