What is the numpy.tile() function in Python?

Overview

In Python, the tile() function is used to construct an array by repeating the input array the number of times as specified by the reps.

Syntax

numpy.tile(A, reps)
Syntax for the tile() function in Python

Parameter value

This function takes the following parameter values:

  • A: The is the input array.
  • reps: This is the number of repetitions for the input array.

Return value

This function returns aa tiled output array.

Example

import numpy as np
# creating an input array
a = np.array([1,2,3,4,5])
# calling the tile() function
my_array = np.tile(a, 2)
# printing the tiled array
print(my_array)

Explanation

  • Line 1: We import the numpy module.
  • Line 3: We create an input array, a, using the array() function.
  • Line 6: We call the tile() function and pass a and 2 as arguments, meaning we are creating a tiled array having two repetitions of the array, a. The result is assigned to a variable, my_array.
  • Line 9: We print the new array, my_array.