1. 创建两个数组
a = np.array([1]*3)
b = np.array([2]*3)
a b
Out:array([1, 1, 1])
array([2, 2, 2])
2. 上下拼接
np.vstack((a,b)) #vertical stack
Out:
array([[1, 1, 1],
[2, 2, 2]])
3. 左右拼接
np.hstack((a,b))
Out:
array([1, 1, 1, 2, 2, 2])
4. 改变维度
a.reshape(3,1)
a.reshape(3,1)
Out:
array([[1],
[1],
[1]])
5. 多数组拼接np.concatenate((a1,a2,a3),axis = 0)
np.concatenate((a,b),axis = 0)
Out:
array([1, 1, 1, 2, 2, 2])
a = np.array([[1, 2], [3, 4]])
b = np.array([[5, 6]])
np.concatenate((a, b), axis=0)
Out:
array([[1, 2],
[3, 4],
[5, 6]])
np.concatenate((a, b.T), axis=1)
Out:
array([[1, 2, 5],
[3, 4, 6]])
附件:
ma.concatenate
Concatenate function that preserves input masks.
array_split
Split an array into multiple sub-arrays of equal or near-equal size.
split
Split array into a list of multiple sub-arrays of equal size.
hsplit
Split array into multiple sub-arrays horizontally (column wise)
vsplit
Split array into multiple sub-arrays vertically (row wise)
dsplit
Split array into multiple sub-arrays along the 3rd axis (depth).
stack
Stack a sequence of arrays along a new axis.
hstack
Stack arrays in sequence horizontally (column wise)
vstack
Stack arrays in sequence vertically (row wise)
dstack
Stack arrays in sequence depth wise (along third dimension)