12.3.10.2.5. Stacking arraysΒΆ

import numpy as np


rg = np.random.default_rng(1)
a = np.floor(10 * rg.random((2, 2)))
b = np.floor(10 * rg.random((2, 2)))
np.vstack((a, b))
array([[5., 9.],
       [1., 9.],
       [3., 4.],
       [8., 4.]])
np.hstack((a, b))
array([[5., 9., 3., 4.],
       [1., 9., 8., 4.]])
np.column_stack((a, b))
array([[5., 9., 3., 4.],
       [1., 9., 8., 4.]])
a[:, np.newaxis]
array([[[5., 9.]],

       [[1., 9.]]])
np.column_stack((a[:, np.newaxis], b[:, np.newaxis]))
array([[[5., 9.],
        [3., 4.]],

       [[1., 9.],
        [8., 4.]]])
np.column_stack is np.hstack
False
np.row_stack is np.vstack
True

Total running time of the script: ( 0 minutes 0.006 seconds)