Numpy row_stack()
function is used to stack 1-Dimensional array row-wise. And 2-Dimensional array is stacked similar to vertical stacking(vstack()
).
np.row_stack(tup)
You pass Numpy arrays in the form of list or tuple to row_stack()
function.
import numpy as np x = np.array([1, 2, 3, 4]) y = np.array([5, 6, 7, 8]) print('First array x:\n', x) print('Second array y:\n', y) print('Row stacked array:\n', np.row_stack((x,y)))
Output of the above program
First array x: [1 2 3 4] Second array y: [5 6 7 8] Row stacked array: [[1 2 3 4] [5 6 7 8]]
import numpy as np x = np.array([[1, 2, 3, 4, 5], [6, 7, 8, 9, 10]]) y = np.array([[11, 12, 13, 14, 15], [16, 17, 18, 19, 20]]) print('First array x:\n', x) print('Second array y:\n', y) print('Row stacked array:\n', np.row_stack((x,y)))
Output of the above program
First array x: [[ 1 2 3 4 5] [ 6 7 8 9 10]] Second array y: [[11 12 13 14 15] [16 17 18 19 20]] Row stacked array: [[ 1 2 3 4 5] [ 6 7 8 9 10] [11 12 13 14 15] [16 17 18 19 20]]