Python – tensorflow.concat()
Last Updated :
26 Jun, 2020
TensorFlow is open-source Python library designed by Google to develop Machine Learning models and deep learning neural networks.
concat() is used to concatenate tensors along one dimension.
Syntax: tensorflow.concat( values, axis, name )
Parameter:
- values: It is a tensor or list of tensor.
- axis: It is 0-D tensor which represents dimension to concatenate.
- name(optional): It defines the name for the operation.
Returns: It returns the concatenated Tensor.
Example 1:
Python3
import tensorflow as tf
t1 = [[[ 1 , 2 ], [ 3 , 4 ]], [[ 5 , 6 ], [ 7 , 8 ]]]
t2 = [[[ 7 , 4 ], [ 8 , 4 ]], [[ 2 , 10 ], [ 15 , 11 ]]]
print ( 't1: ' , t1)
print ( 't2: ' , t2)
res = tf.concat([t1, t2], 2 )
print ( 'Result: ' , res)
|
Output:
t1: [[[1, 2], [3, 4]], [[5, 6], [7, 8]]]
t2: [[[7, 4], [8, 4]], [[2, 10], [15, 11]]]
Result: tf.Tensor(
[[[ 1 2 7 4]
[ 3 4 8 4]]
[[ 5 6 2 10]
[ 7 8 15 11]]], shape=(2, 2, 4), dtype=int32)
Example 2:
Python3
import tensorflow as tf
t1 = [[[ 1 , 2 ], [ 3 , 4 ]], [[ 5 , 6 ], [ 7 , 8 ]]]
t2 = [[[ 7 , 4 ], [ 8 , 4 ]], [[ 2 , 10 ], [ 15 , 11 ]]]
print ( 't1: ' , t1)
print ( 't2: ' , t2)
res = tf.concat([t1, t2], 1 )
print ( 'Result: ' , res)
|
Output:
t1: [[[1, 2], [3, 4]], [[5, 6], [7, 8]]]
t2: [[[7, 4], [8, 4]], [[2, 10], [15, 11]]]
Result: tf.Tensor(
[[[ 1 2]
[ 3 4]
[ 7 4]
[ 8 4]]
[[ 5 6]
[ 7 8]
[ 2 10]
[15 11]]], shape=(2, 4, 2), dtype=int32)
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...