Expand repeated features across an axis
Broadcast-like expansion
TensorFlow · Function
Constructs a new tensor by repeating an input along each dimension. The repetitions are specified by the corresponding entries in multiples.
tf.tile creates a new tensor by repeating the input along every dimension according to the corresponding value in multiples. Each output dimension equals the input dimension multiplied by its repetition count, while the output keeps the input data type.
tf.tile(input: Annotated[Any, TV_Tile_T], multiples: Annotated[Any, TV_Tile_Tmultiples], name=None) -> Annotated[Any, TV_Tile_T]| Name | Type | Description |
|---|---|---|
input | Tensor | Input tensor; it may have any rank. |
multiples | Tensor | One-dimensional int32 or int64 tensor. Its length must equal the number of dimensions in input. |
name | string | Optional operation name. |
A Tensor with the same type as input.
import tensorflow as tf
x = tf.constant([[1, 2, 3], [4, 5, 6]])
repeats = tf.constant([1, 2])
y = tf.tile(x, repeats)
print(y.numpy())
# [[1 2 3 1 2 3]
# [4 5 6 4 5 6]]Repeats each row once and each column twice, producing a tensor with shape (2, 6).
Broadcast-like expansion
Pattern generation
Batch or grid construction
tf.tile repeats an input tensor along each axis and returns a new tensor with the same data type. The output size on axis i is the input size on that axis multiplied by multiples[i].
Follow-up: What happens when multiples is [2, 1] for a rank-2 matrix? The rows are repeated twice, while each row's columns are preserved once.
multiples must be a one-dimensional int32 or int64 tensor. Its length must equal the rank of input, and each value controls repetition along the corresponding dimension.
Follow-up: Why is a rank mismatch invalid? Because TensorFlow cannot associate every input dimension with a repetition count.
For a matrix, multiples [1, 2] leaves the first dimension unchanged and duplicates the values along the second dimension. For example, a 2-by-3 input becomes 2-by-6.
Follow-up: How would [2, 2] affect that same matrix? It would produce a 4-by-6 output by repeating both axes.
tf.concattf.repeattf.stack