w3resource
ankara escort
malatya escort
NumPy Exercises

NumPy: Repeat elements of an array

NumPy: Array Object Exercise-26 with Solution

Write a NumPy program to repeat elements of an array.

Pictorial Presentation:

Python NumPy: Repeat elements of an array

Sample Solution:-

NumPy Code:

import numpy as np
x = np.repeat(3, 4)
print(x)
x = np.array([[1,2],[3,4]])
print(np.repeat(x, 2))

Sample Output:

[3 3 3 3]                                                              
[1 1 2 2 3 3 4 4]

Python Code Editor:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a NumPy program to construct an array by repeating.
Next: Write a NumPy program to find the indices of the maximum and minimum values along the given axis of an array.

What is the difficulty level of this exercise?



New Exercises:R Programming