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.