'Join two 2D numpy array with one row over another

Two numpy arrays, lets say

a = np.array([[1,2], [3,4]])
b = np.array([[5,6], [7,8]])

I would like to combine two arrays into one single array such that the results looks like below array

np.array([[1,2],
          [5,6],
          [3,4],
          [7,8]])

I tried using concatenate, merge function, but cannot able to find pythonic way to solve this. Is there is any in built function to solve my problem.



Solution 1:[1]

You can column_stack + reshape:

out = np.column_stack((a,b)).reshape(4,2)

Output:

array([[1, 2],
       [5, 6],
       [3, 4],
       [7, 8]])

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1