numpy.hstack()用法參考

numpy.hstack(tup)

  • Stack arrays in sequence horizontally (column wise)按順序水平排列數組(不同數組按列拼在一起,比如:第一個數組的第一列和第二個數組的第一列拼接在同一行,以此類推)。
  • This is equivalent to concatenation along the second axis, except for 1-D arrays where it concatenates along the first axis. Rebuilds arrays divided by hsplit.這相當於沿着第二個軸進行連接,除了沿着第一個軸進行連接的一維數組之外。重建被hsplit分割的數組。
  • This function makes most sense for arrays with up to 3 dimensions. For instance, for pixel-data with a height (first axis), width (second axis), and r/g/b channels (third axis). The functions concatenate, stack and block provide more general stacking and concatenation operations.這個函數對於3維以下的數組最有意義。例如,對於具有高度(第一個軸)、寬度(第二個軸)和r/g/b通道(第三個軸)的像素數據。函數級聯,堆棧和塊提供了更一般的堆積和連接操作

  • Parameters

    • 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.除了長度可以是任意的一維數組外,數組必須沿着第二個軸具有相同的形狀。
  • Returns
    stacked:ndarray

    • The array formed by stacking the given arrays.通過疊加給定的數組而形成的數組

示例:

>>>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]])
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章