Skip to content Skip to sidebar Skip to footer

Numpy Concatenate Arrays With Interleaving

I have 4 arrays and I want to concatenate them into one single array with interleaving. How do I do this? >>> import numpy as np >>> a = np.tile(0,(5,2)) >>

Solution 1:

Use np.dstack or np.stack to stack along the last axis that gives us a 3D array and then reshape back to 2D -

np.dstack([a,b,c,d]).reshape(a.shape[0],-1)
np.stack([a,b,c,d],axis=2).reshape(a.shape[0],-1)

Post a Comment for "Numpy Concatenate Arrays With Interleaving"