0.2 数组的拼接
concatenate((a1, a2, …), axis)axis指定沿着哪个轴进行拼接
#一维只有一个方向
x = np.array([1, 2, 3])
y = np.array([3, 2, 1])
np.concatenate([x,y])
array([1, 2, 3, 3, 2, 1])
拼接: 沿着一个指定的轴, 将两个数据拼接成一个数组拼接的过程中, 数组的维度不会发生变化
#所以0轴拼接保列数相同,1轴拼接保行数相同
x2 = np.random.randint(10, size=(3, 4))
x3 = x2.copy()
x2
x3
array([[2, 0, 7, 5],
[9, 0, 2, 7],
[2, 9, 2, 3]])
array([[2, 0, 7, 5],
[9, 0, 2, 7],
[2, 9, 2, 3]])
0.3 数组的拆分
将一个数组分成几个较小的数组
既然可以将多个数组进行对堆叠,自然也可以将一个数组拆分成多个小数组。
使用split,可以指定均匀切割成几份,也可以指定沿着哪个位置进行切割, 还可以指定沿着哪个轴进行切割.
np.split(arr,indices_or_sections,axis)
- indices_or_sections:int或1-D数组。
- 如果indices_or_sections是一个整数N,则数组将被分割沿着’轴’进入N个相等的数组。
- 如果indices_or_sections是排序整数的1-D数组,则为条目指示数组被分割的“轴”的位置。
- 如果索引超