简体   繁体   中英

How to combine two tensor in theano

I am wondering how is it possible to combine two variables, similar to append in python? For example, we have two variables (after feeding with data):

x: with size 1*3 y: with size 1*3

now I want to have a variable, which combine x and y to a size of 1*3*2

Thanks,

One can use theano.tensor.stack to achieve this. Here's a working example:

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

which prints

[[[ 1.  4.]
  [ 2.  5.]
  [ 3.  6.]]]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM