pythonscipyHow do I use the numpy vstack function in Python?
np.vstack
is a function in the NumPy library used to stack arrays in sequence vertically (row wise). It takes a sequence of arrays of the same shape as arguments and returns a single array that is a concatenation of all of the input arrays.
Example
import numpy as np
a = np.array([1, 2, 3])
b = np.array([2, 3, 4])
c = np.vstack((a,b))
print(c)
Output example
[[1 2 3]
[2 3 4]]
The code above uses the np.vstack
function to stack two arrays a
and b
vertically. The output is a single array c
that is the concatenation of a
and b
.
The parts of the code are as follows:

import numpy as np
: This imports the NumPy library asnp
, which provides access to thevstack
function. 
a = np.array([1, 2, 3])
: This creates an arraya
with elements1, 2, 3
. 
b = np.array([2, 3, 4])
: This creates an arrayb
with elements2, 3, 4
. 
c = np.vstack((a,b))
: This uses thenp.vstack
function to stacka
andb
vertically. 
print(c)
: This prints the output of thenp.vstack
function.
Helpful links
More of Python Scipy
 How can I use Python and SciPy to implement a quantum Monte Carlo simulation?
 How do I use Scipy zeros in Python?
 How do I use the scipy ttest_ind function in Python?
 How to use Python, XMLRPC, and NumPy together?
 How can I use the x.shape function in Python Numpy?
 How do I download a Python Scipy .whl file?
 How can I use Python and SciPy to read and write WAV files?
 How do I check the version of Python SciPy I'm using?
 How do I calculate the crosscorrelation of two arrays using Python and NumPy?
 How can I use Python, SciPy and stats.rvs to generate random variables?
See more codes...