Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
w3resource

NumPy: vstack() function

numpy.vstack() function

The vstack() function is used to stack arrays in sequence vertically (row wise).
This is equivalent to concatenation along the first axis after 1-D arrays of shape (N,) have been reshaped to (1,N).
This function makes most sense for arrays with up to 3 dimensions. For instance, for pixel-data with a height (first axis), width (second axis), and r/g/b channels (third axis). T

Syntax:

numpy.vstack(tup)
NumPy manipulation: vstack() function

Version: 1.15.0

Parameter:

Name Description Required /
Optional
tup The arrays must have the same shape along all but the first axis. 1-D arrays must have the same length. Required

Return value:

stacked : ndarray The array formed by stacking the given arrays.

Example-1: numpy.vstack() function

>>> import numpy as np
>>> x = np.array([3, 5, 7])
>>> y = np.array([5, 7, 9])
>>> np.vstack((x,y))
array([[3, 5, 7],
       [5, 7, 9]])

Pictorial Presentation:

NumPy manipulation: vstack() function

Example-2: numpy.vstack() function

>>> import numpy as np
>>> x = np.array([[3], [5], [7]])
>>> y = np.array([[5], [7], [9]])
>>> np.vstack((x,y))
array([[3],
       [5],
       [7],
       [5],
       [7],
       [9]])

Pictorial Presentation:

NumPy manipulation: vstack() function

Python - NumPy Code Editor:

Previous: hstack()
Next: block()