tf.concat
tf.concat是把多个tensor合并成一个,合并增加行:
import tensorflow as tf
tensor_1 = tf.constant([[1, 2],
[3, 4],
[5, 6]] ) # 2*3
tensor_2 = tf.constant([[7, 8],
[9, 10],
[11, 12]]) # 2*3
tf.concat([tensor_1, tensor_2], axis=0)
输出:
<tf.Tensor: shape=(6, 2), dtype=int32, numpy=
array([[ 1, 2],
[ 3, 4],
[ 5, 6],
[ 7, 8],
[ 9, 10],
[11, 12]], dtype=int32)>
增加列:
tf.concat([tensor_1, tensor_2], axis=1)
输出:
<tf.Tensor: shape=(3, 4), dtype=int32, numpy=
array([[ 1, 2, 7, 8],
[ 3, 4, 9, 10],
[ 5, 6, 11, 12]], dtype=int32)>