转载自:https://blog.csdn.net/appleml/article/details/71023039
https://www.cnblogs.com/mdumpling/p/8053474.html
tf.concat(concat_dim, values, name='concat')
t1 = [[1, 2, 3], [4, 5, 6]] t2 = [[7, 8, 9], [10, 11, 12]] tf.concat(0, [t1, t2]) == > [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10, 11, 12]] tf.concat(1, [t1, t2]) ==> [[1, 2, 3, 7, 8, 9], [4, 5, 6, 10, 11, 12]] tf.shape(tf.concat(0, [t3, t4])) ==> [4, 3] tf.shape(tf.concat(1, [t3, t4])) ==> [2, 6]
一维拼接:
t1=tf.constant([1,2,3]) t2=tf.constant([4,5,6]) #concated = tf.concat(1, [t1,t2])这样会报错 t1=tf.expand_dims(tf.constant([1,2,3]),1) t2=tf.expand_dims(tf.constant([4,5,6]),1) concated = tf.concat(1, [t1,t2])#这样就是正确的
如果想沿着tensor新轴连接打包,则tf.concat(axis, [tf.expand_dims(t, axis) for t in tensors]),等价于tf.pack(tensors, axis=axis),tf.pack改名为tf.stack了