1

I would like to augment list from

[1, 2, 3, 4, 5]

to

[1, 1, 2, 2, 3, 3, 4, 4, 5, 5]

If I want to augment likewise n times (like 100 or 500 times), how can I do it? I do not want to do it with regular loop, but using some library like numpy. Any helps?

Many thanks.

Isaac Sim
  • 539
  • 1
  • 7
  • 23

1 Answers1

2

You can do this with numpy's np.repeat:

import numpy as np
a = np.array([1, 2, 3, 4, 5])
np.repeat(a,2)
# array([1, 1, 2, 2, 3, 3, 4, 4, 5, 5])
yatu
  • 86,083
  • 12
  • 84
  • 139
  • 1
    Please flag obvious duplicates like this as such rather than answering. – user3483203 Mar 11 '19 at 09:48
  • user3483203 // I expected it to be duplicate but I asked the question just because I couldn't find one with the keywords that I thought to be related. Sorry for asking a duplicate question. – Isaac Sim Mar 12 '19 at 00:54