numpy.vstack
Stack arrays in sequence vertically (row wise)
垂直(按行)顺序堆叠数组。
Take a sequence of arrays and stack them vertically to make a single array. Rebuild arrays divided by vsplit.
Parameters:
tup : sequence of ndarrays
Tuple containing arrays to be stacked. The arrays must have the same shape along all but the first axis.
Returns:
stacked : ndarray
The array formed by stacking the given arrays.
Examples例子
1 2 3 4 5 | >>> a = np.array([1, 2, 3]) >>> b = np.array([2, 3, 4]) >>> np.vstack((a,b)) array([[1, 2, 3], [2, 3, 4]]) |
1 2 3 4 5 6 7 8 9 | >>> a = np.array([[1], [2], [3]]) >>> b = np.array([[2], [3], [4]]) >>> np.vstack((a,b)) array([[1], [2], [3], [2], [3], [4]]) |
numpy.hstack
Stack arrays in sequence horizontally (column wise).
水平(按列)顺序堆叠数组。
Take a sequence of arrays and stack them horizontally to make a single array. Rebuild arrays divided by hsplit.
Parameters:
tup : sequence of ndarrays
All arrays must have the same shape along all but the second axis.
Returns:
stacked : ndarray
The array formed by stacking the given arrays.
Examples例子
1 2 3 4 | >>> a = np.array((1,2,3)) >>> b = np.array((2,3,4)) >>> np.hstack((a,b)) array([1, 2, 3, 2, 3, 4]) |
1 2 3 4 5 6 | >>> a = np.array([[1],[2],[3]]) >>> b = np.array([[2],[3],[4]]) >>> np.hstack((a,b)) array([[1, 2], [2, 3], [3, 4]]) |