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

NumPy · Function

np.tile

Constructs an array by repeating an input along its axes according to reps. NumPy aligns the input rank and repetition specification by adding leading dimensions or leading repetition counts of one.

How it works

np.tile constructs a new array by repeating the input along each axis according to reps. The number of dimensions is the larger of reps length and the input rank; missing dimensions are handled by prepending axes or repetition counts of one.

Syntax

numpy.tile(A, reps)

Parameters

NameTypeDescription
Aarray_likeThe input array.
repsarray_likeThe number of repetitions of A along each axis.

Returns

The tiled output array, as an ndarray.

Key points

  • Builds an array containing repeated copies of the input, with repetition controlled by reps.
  • The output rank is the larger of the repetition specification length and the input array rank.
  • A lower-rank input gains leading singleton axes when reps describes more dimensions.
  • For a vector, extra dimensions are added at the front before replication.
  • When the input has more axes than reps, leading repetition counts of one are added.
  • Each reps entry controls how many times the corresponding axis is repeated.

Common mistakes

  • Do not use tile as the default substitute for broadcasting; prefer NumPy broadcasting operations and functions.

Example: Repeat a vector across rows

import numpy as np

values = np.array([1, 2, 3])
result = np.tile(values, (2, 1))
print(result)
# [[1 2 3]
#  [1 2 3]]

Creates a two-row array by repeating the one-dimensional input once along its existing axis.

When to use it

Construct a regular tiled layout

Create repeated rows or columns from an existing array.

Replicate multidimensional patterns

Generate repeated blocks for matrix-like data.

Materialize repeated values

Create explicit repeated data when a materialized array is required.

Interview questions

QWhat does np.tile do, and how does it determine the output rank?

np.tile repeats an array according to the counts in reps and returns the tiled output array. If reps has d entries, the result rank is max(d, A.ndim).

Follow-up: How is a one-dimensional input treated with two repetition counts? It is promoted by adding a leading axis, so its shape behaves like (1, n).

QWhat are the parameters of np.tile?

A is the input array-like object, while reps specifies repetitions along each axis. A scalar repetition is accepted, and a sequence supplies one count per represented axis.

Follow-up: What happens when A has more dimensions than reps? Reps is expanded by prepending ones until it matches A.ndim.

QHow does np.tile differ from broadcasting?

The function returns an ndarray containing the repeated input. For example, tiling [0, 1, 2] with (2, 2) produces two rows, each containing the input twice.

Follow-up: When should broadcasting be used instead? Use broadcasting operations when the goal is compatible-shape computation rather than materializing repeated data.

  • numpy.repeat
  • numpy.broadcast_to

Source: numpy.tile — NumPy v2.4 Manual. Checked 2026-10-15.