需求:把所有1拼接在一起,2,3同理
import tensorflow as tf
x = tf.constant([[[[1,1,1]]], [[[2,2,2]]], [[[3,3,3]]]])
y = tf.constant([[[[1,1,1]]], [[[2,2,2]]], [[[3,3,3]]]])
a = [x, y]
with tf.Session() as sess:
print(tf.concat(a, 3).eval())
"""
[[[[1 1 1 1 1 1]]]
[[[2 2 2 2 2 2]]]
[[[3 3 3 3 3 3]]]]
"""
别的玩法
import tensorflow as tf
x = tf.constant([[1, 2],[2,3]])
y = tf.constant([[3,3], [4,5]])
a = [x, y]
with tf.Session() as sess:
print(tf.concat(a, 0).eval())
print(tf.concat(a, 1).eval())
"""
[[1 2]
[2 3]
[3 3]
[4 5]]
----------
[[1 2 3 3]
[2 3 4 5]]
"""