NumPy 的 hstack(~)
方法用于水平连接数组。
参数
1. tup
| array-like
将水平连接的数组。
返回值
一个 Numpy 数组,其中提供的数组水平连接。
例子
连接一维数组
水平连接两个一维NumPy数组:
x = np.array([1,2,3])
y = np.array([4,5,6])
z = np.hstack([x,y])
z
array([1, 2, 3, 4, 5, 6])
请注意,您不限于一次仅连接两个数组 - 您可以传入任意数量的数组。
连接二维数组
要水平连接两个 2D NumPy 数组:
x = np.array([[1,2],[3,4]])
y = np.array([[5,6],[7,8]])
z = np.hstack([x,y])
z
array([[1, 2, 5, 6],
[3, 4, 7, 8]])
为了更容易处理这个问题,这里是x
和y
pretty-formatted:
x = [[1, 2], y = [[5, 6]
[3, 4]] [7, 8]]
相关用法
- Python NumPy hsplit方法用法及代码示例
- Python hashlib.sha3_256()用法及代码示例
- Python help()用法及代码示例
- Python BeautifulSoup has_attr方法用法及代码示例
- Python hasattr方法用法及代码示例
- Python http.HTTPStatus用法及代码示例
- Python hashlib.sha3_512()用法及代码示例
- Python help方法用法及代码示例
- Python hashlib.shake_256()用法及代码示例
- Python hashlib.shake_128()用法及代码示例
- Python NumPy hypot方法用法及代码示例
- Python hashlib.blake2s()用法及代码示例
- Python hashlib.blake2b()用法及代码示例
- Python hasattr()用法及代码示例
- Python html.escape()用法及代码示例
- Python statistics harmonic_mean()用法及代码示例
- Python html.unescape()用法及代码示例
- Python math hypot()用法及代码示例
- Python hash()用法及代码示例
- Python hashlib.sha3_224()用法及代码示例
- Python hex方法用法及代码示例
- Python hex()用法及代码示例
- Python OpenCV haveImageReader()用法及代码示例
- Python http.client.HTTPConnection.set_tunnel用法及代码示例
- Python NumPy histogram方法用法及代码示例
注:本文由纯净天空筛选整理自Isshin Inada大神的英文原创作品 NumPy | hstack method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。