numpy.vstack numpy.hstack

本文详细介绍了NumPy库中数组堆叠的功能,包括垂直堆叠(vstack)和水平堆叠(hstack)的方法。通过实例展示了如何使用这些函数将多个数组组合成一个单一的数组,适用于需要处理多维数据的场景。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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]])
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值