Issue
I want to expand/repeat each element in a 1D array for different times
x = array([7,1,9]) #1d array
rep_size = array([3,2,2]) # repeat number for each element in x
result = arary([7,7,7,1,1,9,9]) #expected result
Is there a numpy function can do this if I don't want to use a for loop. Thanks.
Solution
Use numpy.repeat
:
result = np.repeat(x, rep_size)
output: array([7, 7, 7, 1, 1, 9, 9])
Answered By - mozway
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.