numpy.vstack() in Python
The numpy.vstack() function stacks the arrays in a sequence vertically (row wise).
Syntax
1 2 3 |
numpy.vstack(tup) |
Parameter
tup: This parameter represents the sequence of ‘ndarrays’ where the arrays must have the same shape along all except the first axis.
Return
This function returns the array formed by stacking the given arrays, will be at least 2-D.
Example 1
1 2 3 4 5 6 7 8 9 10 11 12 |
# Python program explaining # numpy.vstack() function import numpy as np inp_array1 = np.array([[ 11, 12, 13], [ -11, -12, -13]] ) print ("Input array: ", inp_array1) inp_array2 = np.array([[ 14, 15, 16], [ -14, -15, -16]] ) print ("Input array: ", inp_array2) #stacks the arrays in a sequence vertically (row wise) out_array = np.vstack((inp_array1, inp_array2)) print ("Output array: ", out_array) |
Output
1 2 3 4 5 6 7 8 9 10 |
Input array: [[ 11 12 13] [-11 -12 -13]] Input array: [[ 14 15 16] [-14 -15 -16]] Output array: [[ 11 12 13] [-11 -12 -13] [ 14 15 16] [-14 -15 -16]] |