Skip to content
masterclassBuddyTech Buzz5 fresh blogs · 5:00 AM IST

TensorFlow · Function

tf.tile

Constructs a new tensor by repeating an input along each dimension. The repetitions are specified by the corresponding entries in multiples.

How it works

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.

Syntax

tf.tile(input: Annotated[Any, TV_Tile_T], multiples: Annotated[Any, TV_Tile_Tmultiples], name=None) -> Annotated[Any, TV_Tile_T]

Parameters

NameTypeDescription
inputTensorInput tensor; it may have any rank.
multiplesTensorOne-dimensional int32 or int64 tensor. Its length must equal the number of dimensions in input.
namestringOptional operation name.

Returns

A Tensor with the same type as input.

Key points

  • The operation builds a new tensor from repeated copies of the input.
  • Each dimension is replicated independently according to its matching value in multiples.
  • To calculate an output dimension, multiply the corresponding input dimension by its repetition count.
  • Replication occurs along the same axis whose count appears at index i in multiples.
  • The input tensor may have any rank.
  • The multiples tensor accepts int32 or int64 values.

Common mistakes

  • multiples must be one-dimensional and contain exactly one repetition count for every input dimension.

Example: Tile a matrix

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).

When to use it

Expand repeated features across an axis

Broadcast-like expansion

Create repeated tensor layouts

Pattern generation

Replicate tensor data across dimensions

Batch or grid construction

Interview questions

QWhat does tf.tile do to a tensor's shape?

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.

QWhat constraints apply to multiples?

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.

QHow do you predict the output shape?

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.concat
  • tf.repeat
  • tf.stack

Source: tf.tile | TensorFlow v2.16.1. Checked 2026-10-15.