一、numpy.hstack()函数
函数原型:numpy.hstack(tup)
其中tup是arrays序列,The arrays must have the same shape, except in the dimensioncorresponding to
axis (the first, by default).
等价于:np.concatenate(tup, axis=1)
numpy.hstack()类似于 行堆积 另起一行
程序实例:
>>> 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.vstack()函数
函数原型:numpy.vstack(tup)
等价于:np.concatenate(tup, axis=0) if tup contains arrays thatare at least 2-dimensional.
numpy.vstack()类似于 列堆积 另起一列
程序实例:

本文介绍了numpy库中的hstack()和vstack()函数。hstack()用于水平堆叠数组,相当于沿轴1进行concatenate操作,而vstack()则用于垂直堆叠数组,沿轴0进行concatenate,适合于数组的列间堆积。
最低0.47元/天 解锁文章
2866

被折叠的 条评论
为什么被折叠?



