Two or more arrays with at least one dimension has the same shape, can be joined together to formulate a new array. These kinds of operations are called stacking. Stacking can be performed either row-wise or column-wise. vstack() is used to stack arrays vertically, such that the resulting array combines all the inputting arrays by rows. hstack() does the similar job, stacking arrays horizontally, i.e. the resulting arrays combines inputting arrays by columns.
#Import Numpy module
import numpy as np
#create two array, of shape (4,2)
C1 = np.ones((4, 2))
C1
#output
array([[1., 1.],
[1., 1.],
[1., 1.],
[1., 1.]])
C2 = np.zeros((4, 2))
C2
#output
array([[0., 0.],
[0., 0.],
[0., 0.],
[0., 0.]])
#vstack() arrays
np.vstack((C1, C2))
#result is an array of shape (8,2)
array([[1., 1.],
[1., 1.],
[1., 1.],
[1., 1.],
[0., 0.],
[0., 0.],
[0., 0.],
[0., 0.]])
#np.hstack((C1, C2))
#result is an array of shape (4,4)
array([[1., 1., 0., 0.],
[1., 1., 0., 0.],
[1., 1., 0., 0.],
[1., 1., 0., 0.]])
Click here to download Python Course Source Files !
For online Python training registration, click here ! Pandas provides flexible ways of generating data…
For online Python training registration, click here ! Data frame is the tabular data object…
Click her for course registration ! When a data frame in Python is created via…
We provide affordable online training course(via ZOOM meeting) for Python and R programming at fundamental…