I have a three-dimensional array (shape is 2,2,3), which can be thought of as a combination of two two-dimensional arrays. I'd like to get these two arrays and put them side-by-side. Here's my starting point:
test1 = np.ndarray((2,2,3))
test1[0] = np.array([[1,2,3],
[4,5,6]])
test1[1] = np.array([[7,8,9],
[10,11,12]])
I can get to the desired result by iterating through the first dimension, likeso:
output = np.ndarray((2,6))
for n_port, port in enumerate(test1):
output[:,n_port*3:(n_port+1)*3] = port
which gives:
array([[ 1., 2., 3., 7., 8., 9.],
[ 4., 5., 6., 10., 11., 12.]])
But I'm wondering if there's a slicker way to do it. The reshape function would be the obvious way to go but it flattens them out, rather than stacking them side-by-side:
test1.reshape((2,6))
array([[ 1., 2., 3., 4., 5., 6.],
[ 7., 8., 9., 10., 11., 12.]])
Any help gratefully received!