How to concatenate two arrays in numpy python by taking first column from the first array and fisrt column from the second, then second column from first and second from the other, etc..? that is if I have A=[a1 a2 a3]
and B=[b1 b2 b3]
I want the resulting array to be [a1 b1 a2 b2 a3 b3]
Few approaches with stacking could be suggested -
np.vstack((A,B)).ravel('F')
np.stack((A,B)).ravel('F')
np.ravel([A,B],'F')
Sample run -
In [291]: A
Out[291]: array([3, 5, 6])
In [292]: B
Out[292]: array([13, 15, 16])
In [293]: np.vstack((A,B)).ravel('F')
Out[293]: array([ 3, 13, 5, 15, 6, 16])
In [294]: np.ravel([A,B],'F')
Out[294]: array([ 3, 13, 5, 15, 6, 16])
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