1 level Horizontal merge
Horizontal: stretched horizontally to the right
Utilization np.hstack()
: the original data size can be inconsistent
Exploitation np.concatenate()
: the original data size can be inconsistent
import numpy as np
# 三个一维数组
array1 = np.array([1, 2, 3])
array2 = np.array([4, 5, 6])
array3 = np.array([7, 8, 9])
merged_array = np.concatenate((array1, array2, array3))
merged_array = np.hstack((array1, array2, array3))
# 得到一维数组
# [1 2 3 4 5 6 7 8 9]
2 Vertical Veitical Merge
Veitical: vertically elongated downward
Utilization np.vstack()
: the original data size should be consistent
import numpy as np
array1 = np.array([1, 2, 3, 4])
array2 = np.array([4, 5, 6, 7])
merged_array = np.vstack((array1, array2))
# 得到二维数组【两行四列】
[[1 2 3 4]
[4 5 6 7]]