-1

I have an array of binary elements size (100,).

I'd like to copy it 8 times, keeping the elements the same and store it as a new array size (800,)

np.copy() can copy it once, but how can I go about copying it 8 times?

Red
  • 26,798
  • 7
  • 36
  • 58
oabdel
  • 37
  • 2
  • 8
  • 1
    Do you mean cycle through the elements 8 times or do you mean repeat each element 8 times and then move onto the next one? – alani Jul 25 '20 at 20:09
  • 1
    Well here are the two options for the different cases I referred to above: `np.tile(a, 8)` for the first and `np.repeat(a, 8)` for the second. – alani Jul 25 '20 at 20:13
  • 2
    Does this answer your question? https://stackoverflow.com/q/25471878/13552470 – Red Jul 25 '20 at 20:24

1 Answers1

2

You can use use numpy.repeat. It repeats array's elements by specifying repeat number:

new_arr = numpy.repeat(old_arr, 8)
Mert Köklü
  • 2,183
  • 2
  • 16
  • 20