1. 程式人生 > 程式設計 >TensorFlow tensor的拼接例項

TensorFlow tensor的拼接例項

TensorFlow提供兩種型別的拼接:

tf.concat(values,axis,name='concat'):按照指定的已經存在的軸進行拼接
tf.stack(values,axis=0,name='stack'):按照指定的新建的軸進行拼接
t1 = [[1,2,3],[4,5,6]]
t2 = [[7,8,9],[10,11,12]]
tf.concat([t1,t2],0) ==> [[1,6],[7,1) ==> [[1,3,7,6,10,12]]
tf.stack([t1,0) ==> [[[1,6]],[[7,12]]]
tf.stack([t1,1) ==> [[[1,9]],[[4,2) ==> [[[1,7],[2,8],[3,10],[5,11],[6,12]]]
t1 = [[1,0) # [2,3] + [2,3] ==> [4,3]
tf.concat([t1,1) # [2,3] ==> [2,6]
tf.stack([t1,3] ==> [2*,3]
tf.stack([t1,2*,2) # [2,2*]

以上這篇TensorFlow tensor的拼接例項就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支援我們。