如何在theano中结合两个张量

时间:2016-01-02 02:48:25

标签: python theano

我想知道如何组合两个变量,类似于在python中追加?例如,我们有两个变量(在用数据提供之后):

x:大小为1 * 3 y:尺寸为1 * 3

现在我想要一个变量,它将x和y组合成1 * 3 * 2

的大小

谢谢,

1 个答案:

答案 0 :(得分:7)

可以使用theano.tensor.stack来实现这一目标。这是一个有效的例子:

Sensor|000000000000000000000001|Sensor (1).csv
Sensor|000000000000000000000002|Sensor (2).csv
Sensor|000000000000000000000003|Sensor (3).csv
StartStop|000000000000000000000001|StartStop (1).csv
StartStop|000000000000000000000002|StartStop (2).csv
StartStop|000000000000000000000003|StartStop (3).csv
StartStop|000000000000000000000000|StartStop.csv

打印

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]])