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 arraya = np.array([1,2,3,4,5])# calling the tile() functionmy_array = np.tile(a, 2)# printing the tiled arrayprint(my_array)
Explanation
- Line 1: We import the
numpymodule. - Line 3: We create an input array,
a, using thearray()function. - Line 6: We call the
tile()function and passaand2as 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.