【TensorFlow】tf.concat()的用法

xiaoxiao2021-07-05  268

tf.concat()是连接两个矩阵的操作。

tf.concat(values,concat_dim, name='concat')

concat_dim代表对矩阵按照某一维度进行操作。

concat_dim=0是按行对矩阵进行拼接。

import tensorflow as tf t1 = [[1, 2, 3], [4, 5, 6]] t2 = [[7, 8, 9], [10, 11, 12]] with tf.Session() as sess: A=tf.concat([t1, t2],0) print(sess.run(A))

结果是  

[[ 1 2 3] [ 4 5 6] [ 7 8 9] [10 11 12]]

concat_dim=1是按照列对矩阵进行拼接。

import tensorflow as tf t1 = [[1, 2, 3], [4, 5, 6]] t2 = [[7, 8, 9], [10, 11, 12]] with tf.Session() as sess: A=tf.concat([t1, t2],1) print(sess.run(A))

结果  

[[ 1 2 3 7 8 9] [ 4 5 6 10 11 12]]

 

转载请注明原文地址: https://www.6miu.com/read-4821333.html

最新回复(0)