The repeat()
function in Python is simply used to repeat the elements of an input array.
The repeat()
function takes the syntax below:
numpy.repeat(a, repeats, axis=None)
The repeat()
function takes the following parameter values:
a
: This is the input array. It is a required parameter. repeats
: This is the number of times for which the elements of the input array are to be repeated. It is a required parameter.axis
: This is the axis along which the repetition is made. It is an optional parameter.The repeat()
function returns an array of the same shape as the input array.
import numpy as np# creating an input arraya = np.array([1,2,3,4,5])# calling the repeat() functionmy_array = np.repeat(a, 2)print(my_array)
numpy
module.a
, using the array()
function.repeat()
function and pass a
and 2
as arguments. The function will create an array in which the element a
will be repeated twice.my_array
.