<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/tensorflow/blob/v2.21.0/tensorflow/python/ops/array_ops.py#L1350-L1442) |

Concatenates tensors along one dimension.

#### View aliases


**Compat aliases for migration**

See
[Migration guide](https://www.tensorflow.org/guide/migrate) for
more details.

[`tf.compat.v1.concat`](https://www.tensorflow.org/api_docs/python/tf/concat)

<br />

    tf.concat(
        values, axis, name='concat'
    )

### Used in the notebooks

| Used in the guide | Used in the tutorials |
|---|---|
| - [Better performance with the tf.data API](https://www.tensorflow.org/guide/data_performance) - [Ragged tensors](https://www.tensorflow.org/guide/ragged_tensor) - [TensorFlow basics](https://www.tensorflow.org/guide/basics) - [Quickstart for the TensorFlow Core APIs](https://www.tensorflow.org/guide/core/quickstart_core) - [Customizing what happens in \`fit()\` with TensorFlow](https://www.tensorflow.org/guide/keras/custom_train_step_in_tensorflow) | - [Simple audio recognition: Recognizing keywords](https://www.tensorflow.org/tutorials/audio/simple_audio) - [Learned data compression](https://www.tensorflow.org/tutorials/generative/data_compression) - [Integrated gradients](https://www.tensorflow.org/tutorials/interpretability/integrated_gradients) - [Transfer learning for video classification with MoViNet](https://www.tensorflow.org/tutorials/video/transfer_learning_with_movinet) - [Video classification with a 3D convolutional neural network](https://www.tensorflow.org/tutorials/video/video_classification) |

See also [`tf.tile`](https://www.tensorflow.org/api_docs/python/tf/tile), [`tf.stack`](https://www.tensorflow.org/api_docs/python/tf/stack), [`tf.repeat`](https://www.tensorflow.org/api_docs/python/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 the `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)>

> [!NOTE]
> **Note:** If you are concatenating along a new axis consider using stack. E.g.

    tf.concat([tf.expand_dims(t, axis) for t in tensors], axis)

can be rewritten as

    tf.stack(tensors, axis=axis)

<br />

<br />

<br />

| ## Args ||
|---|---|
| `values` | A list of `Tensor` objects or a single `Tensor`. |
| `axis` | 0-D `int32` `Tensor`. Dimension along which to concatenate. Must be in the range `[-rank(values), rank(values))`. As in Python, indexing for axis is 0-based. Positive axis in the rage of `[0, rank(values))` refers to `axis`-th dimension. And negative axis refers to `axis + rank(values)`-th dimension. |
| `name` | A name for the operation (optional). |

<br />

<br />

<br />

<br />

| ## Returns ||
|---|---|
| A `Tensor` resulting from concatenation of the input tensors. ||

<br />