I am trying to modify a NumPy array by adding a row of zeros after each row. My matrix has 491 rows and I should end up with a matrix that has 982 rows. I tried multiple ways using np.repeat
, np.tile
and so on to no avail.
Can anyone help me with this issue?
You could do this by initialising a 982-row array first and then filling alternate rows, for example (5 columns):
a=np.zeros((982,5))
b=np.random.randint(0,100,(491,5)) # your 491 row matrix
a[::2] = b
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With