简体   繁体   English

如何拆分张量然后连接它?

[英]How do I split a tensor and then concatenate it?

My input data is of the form [None, 2, 100], basically I have a bunch of 2 cell arrays that each contain vectors of size 100. I want to run each vector through a separate input layer, and after that layer concatenate the results into one vector.我的输入数据的形式为 [None, 2, 100],基本上我有一堆 2 个元胞数组,每个数组包含大小为 100 的向量。我想通过单独的输入层运行每个向量,然后在该层之后连接结果到一个向量中。

My questions are as follows: Given a tensor of shape [None, 2, 100], how do I transform it to be of size [None, 100]?我的问题如下:给定一个形状为 [None, 2, 100] 的张量,如何将其转换为 [None, 100] 的大小? Then, give two tensors, of size [None, 50], how do I concatenate them to be of size [None, 100]?然后,给两个大小为 [None, 50] 的张量,如何将它们连接成大小为 [None, 100]?

Thanks in advance.提前致谢。

  1. You can use numpy-like indexing, tf.slice or tf.unpack您可以使用类似 numpy 的索引、 tf.slicetf.unpack

     c = tf.placeholder(tf.int32, shape=[None, 2, 100]) d = c[:,0,:] e = tf.squeeze(tf.slice(c, [0,1,0], [-1, 1, -1]), squeeze_dims=[1]) [d, e] = tf.unpack(c, axis=1)
  2. concatenation:串联:

     a = tf.placeholder(tf.int32, shape=[None, 50]) b = tf.placeholder(tf.int32, shape=[None, 50]) tf.concat(1, [a,b]).get_shape() TensorShape([Dimension(None), Dimension(100)])

你也可以做这样的事情:

tf.concat(tf.unstack(feature_output), 0)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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