# numpy.repeat () in Python

Parameters :

`  array:  [array_like] Input array.  repetitions:  No. of repetitions of each array elements along the given axis.  axis:  Axis along which we want to repeat values. By default, it returns a flat output array. `

Return:

` An array with repetitions of array - arr elements as per repetitions, number of times we want to repeat arr `

Code 1:

 ` # Python program illustrating ` ` # numpy.repeat () `   ` import ` ` numpy as geek `   ` # 1D ` ` arr ` ` = ` ` geek.arange ( ` ` 5 ` `) ` ` print ` ` (` ` "arr:" ` `, arr) `   ` repetitions ` ` = ` ` 2 ` ` a ` ` = ` ` geek.repeat (arr, repetitions) ` ` print ` ` (` ` "Repeating arr 2 times:" ` `, a) ` ` print ` ` (` ` "Shape:" ` `, a.shape) `   ` repetitions ` ` = ` ` 3 ` ` a ` ` = ` ` geek.repeat (arr, repetitions) ` ` print ` ` (` ` "Repeating arr 3 times:" ` `, a) ` ` # [0 0 0 ..., 4 4 4] means [0 0 0 1 1 1 2 2 2 3 3 3 4 4 4] ` ` # since it was long output, so it uses [...] ` ` print ` ` (` ` "Shape:" ` `, a.shape) `

Output:

` arr: [0 1 2 3 4] Repeating arr 2 times: [0 0 1 1 2 2 3 3 4 4] Shape: (10,) Repeating arr 3 times: [0 0 0 ..., 4 4 4] Shape: (15,) `

Code 2:

 ` # Python program illustrating ` ` # numpy.repeat () `   ` import ` ` numpy as geek `   ` arr = geek.arange ( 6 ). reshape ( 2 , 3 ) `` print ( " arr: " , arr)    repetitions = 2 print ( "Repeating arr:" , geek.repeat (arr, repetitions, 1 )) print ( "arr Shape:" , geek. repeat (arr, repetitions) .shape)      repetitions = 2 print ( "Repeating arr:" , geek.repeat (arr, repetitions, 0 )) print ( "arr Shape:" , geek.repeat (arr, repetitions) .shape)   repetitions = 3 print ( "Repeating arr: " , geek.repeat (arr, repetitions, 1 )) print ( "arr Shape:" , geek.repeat (arr, repetitions) .shape) `

Output:

` arr: [[0 1 2] [3 4 5]] Repeating arr: [[0 0 1 1 2 2] [3 3 4 4 5 5]] arr Shape: (12,) Repeating arr: [[ 0 1 2] [0 1 2] [3 4 5] [3 4 5]] arr Shape: (12,) Repeating arr: [[0 0 0 ..., 2 2 2] [3 3 3 ... , 5 5 5]] arr Shape: (18,) `

Notes:
These codes will not work for online IDs. Please run them on your systems to see how they work

## Shop Best laptop for Excel

\$ Best laptop for Solidworks

\$399+ Best laptop for Roblox

\$399+ Best laptop for development

\$499+ Best laptop for Cricut Maker

\$299+ Best laptop for hacking

\$890 Best laptop for Machine Learning

\$699+ Raspberry Pi robot kit

\$150

Latest questions

PythonStackOverflow

Common xlabel/ylabel for matplotlib subplots

PythonStackOverflow

Check if one list is a subset of another in Python

PythonStackOverflow

How to specify multiple return types using type-hints

PythonStackOverflow

Printing words vertically in Python

PythonStackOverflow

Python Extract words from a given string

PythonStackOverflow

Why do I get "Pickle - EOFError: Ran out of input" reading an empty file?

PythonStackOverflow

Python os.path.join () method

PythonStackOverflow

Flake8: Ignore specific warning for entire file

## Wiki

Python | How to copy data from one Excel sheet to another

Common xlabel/ylabel for matplotlib subplots

Check if one list is a subset of another in Python

How to specify multiple return types using type-hints

Printing words vertically in Python

Python Extract words from a given string

Cyclic redundancy check in Python

Finding mean, median, mode in Python without libraries