Here are some more ways to do the same thing. In terms of readability, numpy.ndarray.flatten is more straightforward.
Input arrays:
In [207]: arr1
Out[207]:
array([[0.34, 0.26, 0.76],
[0.79, 0.82, 0.37],
[0.93, 0.87, 0.94]])
In [208]: arr2
Out[208]:
array([[0.21, 0.73, 0.69],
[0.35, 0.24, 0.53],
[0.01, 0.42, 0.5 ]])
As a first step, flatten them:
In [209]: arr1_flattened = arr1.flatten()[:, np.newaxis]
In [210]: arr1_flattened
Out[210]:
array([[0.34],
[0.26],
[0.76],
[0.79],
[0.82],
[0.37],
[0.93],
[0.87],
[0.94]])
In [211]: arr2_flattened = arr2.flatten()[:, np.newaxis]
In [212]: arr2_flattened
Out[212]:
array([[0.21],
[0.73],
[0.69],
[0.35],
[0.24],
[0.53],
[0.01],
[0.42],
[0.5 ]])
Then concatenate or stack them:
# just horizontally stack (np.hstack) the flattened arrays
In [213]: np.hstack([arr1_flattened, arr2_flattened])
Out[213]:
array([[0.34, 0.21],
[0.26, 0.73],
[0.76, 0.69],
[0.79, 0.35],
[0.82, 0.24],
[0.37, 0.53],
[0.93, 0.01],
[0.87, 0.42],
[0.94, 0.5 ]])
In one-line:
In [205]: np.hstack([arr1.flatten()[:, None], arr2.flatten()[:, None]])
Out[205]:
array([[0.34, 0.21],
[0.26, 0.73],
[0.76, 0.69],
[0.79, 0.35],
[0.82, 0.24],
[0.37, 0.53],
[0.93, 0.01],
[0.87, 0.42],
[0.94, 0.5 ]])
# same thing can be done using np.concatenate
In [206]: np.concatenate([arr1.flatten()[:, None], arr2.flatten()[:, None]], axis=1)
Out[206]:
array([[0.34, 0.21],
[0.26, 0.73],
[0.76, 0.69],
[0.79, 0.35],
[0.82, 0.24],
[0.37, 0.53],
[0.93, 0.01],
[0.87, 0.42],
[0.94, 0.5 ]])
Note that all the stacking methods (stack, hstack, vstack, dstack, column_stack), call numpy.concatenate() under the hood.