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]])

你可能感兴趣的:(Numpy)