numpy的concatenate函数

concatenate((a1, a2, …), axis=0)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
concatenate(...)
concatenate((a1, a2, ...), axis=0)

Join a sequence of arrays along an existing axis.

Parameters
----------
a1, a2, ... : sequence of array_like
The arrays must have the same shape, except in the dimension
corresponding to `axis` (the first, by default).
axis : int, optional
The axis along which the arrays will be joined. Default is 0.

Returns
-------
res : ndarray
The concatenated array.

See Also
--------

Parameters参数

传入的参数必须是一个多个数组的元组或者列表

另外需要指定拼接的方向,默认是 axis = 0,也就是说对0轴的数组对象进行纵向的拼接(纵向的拼接沿着axis= 1方向);注:一般axis = 0,就是对该轴向的数组进行操作,操作方向是另外一个轴,即axis=1。
拼接的数组要满足在拼接方向axis轴上数组间的形状一致即可

1
2
a = np.array([[1, 2], [3, 4]])
b = np.array([[5, 6]])
1
np.concatenate((a, b), axis=0)
1
2
3
array([[1, 2],
[3, 4],
[5, 6]])