python中科学计算包numpy中矩阵的合并,需要用到如下两个函数:
列合并:np.column_stack() ,其中函数参数为一个tuple
行合并:np.row_stack(),其中函数参数为一个tuple
>>> import numpy as np
>>> a = np.arange(8).reshape(4, -1)
>>> print(a)
[[0 1]
[2 3]
[4 5]
[6 7]]
>>> b = np.arange(8, 16).reshape(4, -1)
>>> print(b)
[[ 8 9]
[10 11]
[12 13]
[14 15]]
>>> c = np.column_stack((a, b))
>>> print(c)
[[ 0 1 8 9]
[ 2 3 10 11]
[ 4 5 12 13]
[ 6 7 14 15]]
>>> d = np.row_stack((a, b))
>>> print(d)
[[ 0 1]
[ 2 3]
[ 4 5]
[ 6 7]
[ 8 9]
[10 11]
[12 13]
[14 15]]