np.vstack in python code example

Example 1: python numpy vstack

>>> a = np.array([1, 2, 3])
>>> b = np.array([2, 3, 4])
>>> np.vstack((a,b))
array([[1, 2, 3],
       [2, 3, 4]])

Example 2: numpy stack arrays vertically

import numpy as np
# ensure same shape of arrays to be stacked.
a = np.arange(10).reshape(2,-1)
b = np.repeat(1, 10).reshape(2,-1)
# use vstack() to stack by row.
out = np.vstack((a,b))
## print output
print(out)
# a
# b

Example 3: python numpy vstack

>>> a = np.array([[1], [2], [3]])
>>> b = np.array([[2], [3], [4]])
>>> np.vstack((a,b))
array([[1],
       [2],
       [3],
       [2],
       [3],
       [4]])

Example 4: np.vstack python

import numpy as np
a = np.array([1, 2, 3])
b = np.array([2, 3, 4])
np.vstack((a,b))