Reputation: 183
I want to insert a numpy array A of size 508x12 into another numpy array B of size 508x13 resulting in an array of size 508x25. But here is the thing, i don't just want to concatanete them, but insted insert the array at one specific column location c.
How would I do that?, I have tried:
C = np.insert(B, c, A, axis=1)
Upvotes: 0
Views: 899
Reputation: 397
Just split up the concatenation like @brezniczky suggested. Alternatively, use hstack:
import numpy as np
a = np.ones((508,12))
b = np.zeros((508,13))
col = 3
final = np.hstack((b[:,0:col],a,b[:,col:]))
print(final[0])
[0. 0. 0. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 1. 0. 0. 0. 0. 0. 0. 0. 0. 0. 0.]
In this scenario hstack and concatenation with axis=1 are the same, I just prefer hstack for better readability
Upvotes: 1