numpy.vstack() in Python

The Python numpy.vstack() function used to stack the sequence of input arrays vertically to make a single array and returns at least 2D array formed by stacking given array.

Basic Syntax

Following is the basic syntax for numpy.vstack() function in Python:

numpy.vstack(tup)

And the parameters are:

ParameterDescription
tup[SQUESNCE OF NDARRAY]. Tuples holding arrays to be stacked.

Return Value

This function returns at least 2D array created by stacking given array.

Example

Following are the examples:

Example 1

The output for the above program is as given below:

First input array:
[2, 3, 4, 8]
Second input array:
[10, 12, 14, 16]
Vertically stacked array:
[[2, 3, 4, 8],
[10, 12, 14, 16]]

Example 2

The output for the above program is as given below:

First Input array :
[[1 2 3 4]
[5 6 7 8]]
Second Input array :
[[ 9 10 11 12]
[13 14 15 16]]
Vertically stacked array :
[[ 1 2 3 4]
[ 5 6 7 8]
[ 9 10 11 12]
[13 14 15 16]]

LEAVE A REPLY

Please enter your comment!
Please enter your name here