如何在theano中组合两个张量
How to combine two tensor in theano
我想知道如何将两个变量组合起来,类似于 python 中的追加?例如,我们有两个变量(输入数据后):
x: 尺寸为 1*3
y:大小为 1*3
现在我想要一个变量,它将 x 和 y 组合成 1*3*2 的大小
谢谢,
可以使用 theano.tensor.stack 来实现这一点。这是一个工作示例:
import theano
import theano.tensor as tt
x = tt.matrix()
y = tt.matrix()
z = tt.stack([x, y], axis=2)
f = theano.function([x, y], z)
print f([[1, 2, 3]], [[4, 5, 6]])
打印
[[[ 1. 4.]
[ 2. 5.]
[ 3. 6.]]]
我想知道如何将两个变量组合起来,类似于 python 中的追加?例如,我们有两个变量(输入数据后):
x: 尺寸为 1*3 y:大小为 1*3
现在我想要一个变量,它将 x 和 y 组合成 1*3*2 的大小
谢谢,
可以使用 theano.tensor.stack 来实现这一点。这是一个工作示例:
import theano
import theano.tensor as tt
x = tt.matrix()
y = tt.matrix()
z = tt.stack([x, y], axis=2)
f = theano.function([x, y], z)
print f([[1, 2, 3]], [[4, 5, 6]])
打印
[[[ 1. 4.]
[ 2. 5.]
[ 3. 6.]]]