tf.concat()

轉載自:https://blog.csdn.net/appleml/article/details/71023039html

            http://www.javashuo.com/article/p-qqjrtmsp-bx.htmlapp

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] 

一維拼接:spa

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了.net

相關文章
相關標籤/搜索