Suppose I have two 2D matrix A and B, I want to concatenate each column in A with the respective column in B. For example:
A = array([[1, 1],
[1, 1]])
B = array([[2, 3],
[2, 3]])
So the result I expect is:
array([[1, 2, 1, 3],
[1, 2, 1, 3]])
You can try concatenate the two arrays, then rearrange the data with reshape
and transpose
:
x = np.concatenate((A, B)).reshape(2,2,2)
x
# array([[[1, 1],
# [1, 1]],
# [[2, 3],
# [2, 3]]])
x.transpose(1,2,0).reshape(2,4)
# array([[1, 2, 1, 3],
# [1, 2, 1, 3]])
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