1. np.vstack(tup):
在竖直方向上堆叠,即增加行。
tup : sequence of ndarrays
The arrays must have the same shape along all but the first axis.
1-D arrays must have the same length.
每个一个arrays在第一个维度上必须有相同的形状,对于二维数据,则必须有相同的列。




从结果上可以看出,a1和a2和a3在第一个维度上(列)具有相同的形状(均为2),因此可以两两进行堆叠。arr1和arr2也有相同的形状(在第一维度上),也可以堆叠,但是其与arr3在第一维度上不具有相同的形状(前者为3,后者为2),所以,没法在垂直方向进行堆叠。
2. np.hstack(tup)
在水平方向想堆叠,即增加列。
tup : sequence of ndarrays
The arrays must have the same shape along all but the second axis,
except 1-D arrays which can be any length.
每个一个arrays在第二个维度上必须有相同的形状,对于二维数据,则必须有相同的行。

由于arr1和arr2和arr3在第二维度(行)上具有相同的形状,a1和a2在第二维度上具有相同的形状,所以可以进行水平的堆叠,而a1和a2与a3不具有相同的形状在行上,所以无法进行堆叠。
注释:对于一维度数组,是没有要求的,可以任意形状。因为第二个维度(行)都是1
3. array的个数可以为多个(>=2)

网友评论