0

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!

1 Answer 1

1

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])
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.