View source on GitHub
|
Concatenates tensors along one dimension.
tf.concat(
values, axis, name='concat'
)
Used in the notebooks
| Used in the guide | Used in the tutorials |
|---|---|
See also tf.tile, tf.stack, tf.repeat.
Concatenates the list of tensors values along dimension axis. If
values[i].shape = [D0, D1, ... Daxis(i), ...Dn], the concatenated
result has shape
[D0, D1, ... Raxis, ...Dn]
where
Raxis = sum(Daxis(i))
That is, the data from the input tensors is joined along the axis
dimension.
The number of dimensions of the input tensors must match, and all dimensions
except axis must be equal.
For example:
t1 = [[1, 2, 3], [4, 5, 6]]t2 = [[7, 8, 9], [10, 11, 12]]tf.concat([t1, t2], 0)<tf.Tensor: shape=(4, 3), dtype=int32, numpy=array([[ 1, 2, 3],[ 4, 5, 6],[ 7, 8, 9],[10, 11, 12]], dtype=int32)>
tf.concat([t1, t2], 1)<tf.Tensor: shape=(2, 6), dtype=int32, numpy=array([[ 1, 2, 3, 7, 8, 9],[ 4, 5, 6, 10, 11, 12]], dtype=int32)>
As in Python, the axis could also be negative numbers. Negative axis
are interpreted as counting from the end of the rank, i.e.,
axis + rank(values)-th dimension.
For example:
t1 = [[[1, 2], [2, 3]], [[4, 4], [5, 3]]]t2 = [[[7, 4], [8, 4]], [[2, 10], [15, 11]]]tf.concat([t1, t2], -1)<tf.Tensor: shape=(2, 2, 4), dtype=int32, numpy=array([[[ 1, 2, 7, 4],[ 2, 3, 8, 4]],[[ 4, 4, 2, 10],[ 5, 3, 15, 11]]], dtype=int32)>
tf.concat([tf.expand_dims(t, axis) for t in tensors], axis)
can be rewritten as
tf.stack(tensors, axis=axis)
Returns | |
|---|---|
A Tensor resulting from concatenation of the input tensors.
|
View source on GitHub