1

I'm trying to add a new array to another array at after row 1,

a=np.arange(1,17).reshape(4,4)
b=np.zeros((1,4),dtype=np.uint8)
c=np.concatenate((a,b),0)

When i try this it adds it after the last row

[[ 1  2  3  4]
 [ 5  6  7  8]
 [ 9 10 11 12]
 [13 14 15 16]
 [ 0  0  0  0]]

I want to add it after row 1 so it should look like this

[[ 1  2  3  4]
 [ 5  6  7  8]
 [ 0  0  0  0]
 [ 9 10 11 12]
 [13 14 15 16]]
1
  • 1
    c[[0,1,4,2,3],:] produces the desired array. Commented Nov 2, 2019 at 16:32

1 Answer 1

0

c = np.insert(a, 2, b, axis=0)

Numpy Insert (documentation)

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.