Tensorflow Learning Notes-tf.concat()

tf.concat() is a function that concatenates tensors , lists or numpy array along with one dimention,and the function name is the short cuting of word concatenate.

  • tf.concat(input,axis)
  • inpus ==> A tensor,list or a numpy arry
  • axis   ==> The dimention,which is concatenates
import tensorflow as tf
#tf.concat(concat_dim,values,name)
a=[[1,1,1],[2,2,2]]#list shape=(2,3) axis=0 ==> (4,3)
b=[[3,3,3],[4,4,4]]#list shape=(2,3) axis=1 ==> (2,6)
                   #list shape=(2,3) axis=0 ==> (1,6)
c=tf.concat([a,b],axis=0)
sess=tf.Session()
print(sess.run(c))

Result:

axis=0:[[1,1,1]                    axis=1:[[1,1,1,2,2,2]

              [2,2,2]                                  [3,3,3,4,4,4]]

              [3,3,3]

              [4,4,4]]

The list a,b are both shape of (2,3) list,when axis=0,it concatenates along with the first dimention that is 2,so,it produceed a shape of (4,3) tensor.similarly,when axis=1,it concatenates along with the second dimention that is 3,so,it produced a 2D tensor with shape of (2,6).In conculsion,tf.concat is a very useful function when we want to combine several tensor to one.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章