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。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。