import numpy as np
a = np.array([1, 2])
b = np.array([5, 6])
c = np.array([3, 4])
print(np.concatenate((a,b,c)))
运行结果:
import numpy as np
a = np.array([[1, 2],[3,4]])
b = np.array([[5, 6],[4,5],[3,1],[3,2]])
print('将b进行转置')
print(b.T) # 将b进行转置 这样能保证与a行数相同
print('将a和b按行拼接')
print(np.concatenate((a,b),axis=0)) # 按行拼接
print('将a和b按列拼接')
print(np.concatenate((a,b.T),axis=1)) # 按列拼接
对于一维数组,情况如下:
import numpy as np
a=np.array([1,2])
b=np.array([3,4])
print('一维数组拼接:',np.append(a,b))
import numpy as np
a1 = np.array([[1, 2], [3, 4]])
b1 = np.array([[5, 6],[2,3]])
print('二维数组拼接:',np.append(a1,b1))
print('二维数组列拼接:')
print(np.append(a1,b1,axis=1))
print('二维数组行拼接:')
print(np.append(a1,b1,axis=0))
运行结果: