Reputation: 59
I have the following numpy array (as an example):
[0,1,5,4,3]
Is there any way to "repeat" this array, but in a specific way: I need a final array of shape 25 but arranged in a way that firs I would have 5 zeros, then- 5 ones, then- 5 fives, etc. Example of desired output:
[0,0,0,0,0,1,1,1,1,1,
5,5,5,5,5,4,4,4,4,4
3,3,3,3,3]
if I do np.append(arr, arr)
- it will give me two initial sequenced arrays, and this is not my goal
BTW, my real array is not sorted and should remain unsorted in the end.
Thanks in advance!
Upvotes: 0
Views: 36
Reputation: 8987
Use np.repeat
.
>>> np.repeat([0,1,5,4,3], 5)
array([0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 5, 5, 5, 5, 5, 4, 4, 4, 4, 4, 3, 3,
3, 3, 3])
Upvotes: 1