Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

Python NumPy repeat Function Example Working with 1D array

# welcome to softhunt.net
# Python Program illustrating
# numpy.repeat()

import numpy as np

#Working on 1D
arr = np.arange(5)
print("arr : 
", arr)

repetitions = 2
a = np.repeat(arr, repetitions)
print("
Repeating arr 2 times : 
", a)
print("Shape : ", a.shape)

repetitions = 3
a = np.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)
Source by softhunt.net #
 
PREVIOUS NEXT
Tagged: #Python #NumPy #repeat #Function #Example #Working #array
ADD COMMENT
Topic
Name
4+6 =