tf.concat = (tensor, axis=0)
tensor需要拼接的張量
axis維度佣耐,當(dāng)axis=0時嘀倒,在第0個維度拼接(按行拼接,即列拼接)鸽疾,當(dāng)axis=1時吊洼,在第1個維度拼接(按列拼接,即行拼接)
t1 = tf.constant([[1, 2, 3], [4, 5, 6]], dtype=tf.float32)
t2 = tf.constant([[7, 8, 9], [10, 11, 12]], dtype=tf.float32)
t3 = [[1, 2, 3], [4, 5, 6]]
t4 = [[7, 8, 9], [10, 11, 12]]
T1 = tf.concat([t1, t2], 0)
T2 = tf.concat([t1, t2], 1)
T3 = tf.concat([t3, t4], 0)
T4 = tf.concat([t3, t4], 1)
with tf.Session() as sess:
print('維度0拼接:\n',sess.run(T1)) # 浮點數(shù)
print('='*30)
print('維度1拼接:\n',sess.run(T2)) # 浮點數(shù)
print('維度0拼接:\n',sess.run(T3)) # 整數(shù)
print('='*30)
print('維度1拼接:\n',sess.run(T4)) # 整數(shù)
維度0拼接:
[[ 1. 2. 3.]
[ 4. 5. 6.]
[ 7. 8. 9.]
[10. 11. 12.]]
==============================
維度1拼接:
[[ 1. 2. 3. 7. 8. 9.]
[ 4. 5. 6. 10. 11. 12.]]
維度0拼接:
[[ 1 2 3]
[ 4 5 6]
[ 7 8 9]
[10 11 12]]
==============================
維度1拼接:
[[ 1 2 3 7 8 9]
[ 4 5 6 10 11 12]]