import numpy as np
append
array3= np.append(array1,array2)
两个数组拉伸一维拼接array3= np.append(array1,array2,axis=0)
两个数组按列拼接array3= np.append(array1,array2,axis=1)
两个数组按行拼接stack
array3= np.stack(array1,array2)
两个数组组合为高维矩阵array3= np.vstack(array1,array2)
两个数组按列拼接array3= np.hstack(array1,array2)
两个数组按行拼接concatenate
array3= np.concatenate((array1,array2))
默认按列拼接array3= np.concatenate((array1,array2),axis=0)
两个数组按列拼接array3= np.concatenate((array1,array2,axis=1))
两个数组按列拼接>>> import numpy as np
>>> a = np.array([[1,1,1],[2,2,2]])
>>> b = 2*np.array([[1,1,1],[2,2,2]])
>>> a
array([[1, 1, 1],
[2, 2, 2]])
>>> b
array([[2, 2, 2],
[4, 4, 4]])
>>> k = np.append(a,b)
>>> k
array([1, 1, 1, 2, 2, 2, 2, 2, 2, 4, 4, 4])
>>> c = np.append(a,b,axis=0)
>>> c
array([[1, 1, 1],
[2, 2, 2],
[2, 2, 2],
[4, 4, 4]])
>>> d = np.append(a,b,axis=1)
>>> d
array([[1, 1, 1, 2, 2, 2],
[2, 2, 2, 4, 4, 4]])
>>> e = np.stack((a,b))
>>> e
array([[[1, 1, 1],
[2, 2, 2]],
[[2, 2, 2],
[4, 4, 4]]])
>>> f = np.vstack((a,b))
>>> f
array([[1, 1, 1],
[2, 2, 2],
[2, 2, 2],
[4, 4, 4]])
>>> g = np.hstack((a,b))
>>> g
array([[1, 1, 1, 2, 2, 2],
[2, 2, 2, 4, 4, 4]])
>>> h = np.concatenate((a,b))
>>> h
array([[1, 1, 1],
[2, 2, 2],
[2, 2, 2],
[4, 4, 4]])
>>> i = np.concatenate((a,b),axis=0)
>>> i
array([[1, 1, 1],
[2, 2, 2],
[2, 2, 2],
[4, 4, 4]])
>>> j = np.concatenate((a,b),axis=1)
>>> j
array([[1, 1, 1, 2, 2, 2],
[2, 2, 2, 4, 4, 4]])
>>>
更多
Python
数据科学相关见专题Python数据科学技能索引