numpy.vstack numpy.hstack

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例子

>>> a = np.array([1, 2, 3])
>>> b = np.array([2, 3, 4])
>>> np.vstack((a,b))
array([[1, 2, 3],
       [2, 3, 4]])

>>> 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例子

>>> a = np.array((1,2,3))
>>> b = np.array((2,3,4))
>>> np.hstack((a,b))
array([1, 2, 3, 2, 3, 4])
>>> a = np.array([[1],[2],[3]])
>>> b = np.array([[2],[3],[4]])
>>> np.hstack((a,b))
array([[1, 2],
       [2, 3],
       [3, 4]])
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章