Numpy 的 hypot(~)
方法計算給定三角形兩條邊的斜邊。
參數
1. x1
| array-like
三角形的第一條邊。
2. x2
| array-like
三角形的第二條邊。
3. out
| Numpy array
| optional
您可以將計算結果放入 out
指定的數組中,而不是創建新數組。
4. where
| boolean
的array
| optional
標記為 False 的值將被忽略,即它們的原始值將未被初始化。如果指定了 out 參數,行為會略有不同 - 原始值將保持不變。由於這讓許多人感到困惑,請查看下麵的示例。
返回值
保存斜邊的 Numpy 數組。
例子
基本用法
np.hypot(3,4)
5.0
np.hypot([1,3],[1,4])
array([1.41421356, 5. ])
這裏,邊長為 1 的直角三角形的斜邊是 2 的平方根。
指定輸出數組
a = np.zeros(2)
np.hypot([1,3],[1,4], out=a)
a
array([1.41421356, 5. ])
在這裏,我們將結果輸出到數組 a
中。
指定布爾掩碼
np.hypot([1,3], [1,4], where=[False, True])
array([2.34e-324, 5. ])
這裏,僅使用第二個數字進行計算,因為它在掩碼中具有相應的布爾值True
。您應該注意到 False
的值如何產生奇怪的結果 - 事實上,您應該忽略它們,因為它們是沒有實際用途的未初始化數字。
現在,如果您指定了 out
參數,而不是未初始化的值,則原始值將保持不變:
a = np.zeros(2)
np.hypot([1,3], [1,4], out=a where=[False, True])
a
array([0., 0.])
相關用法
- Python math hypot()用法及代碼示例
- Python hashlib.sha3_256()用法及代碼示例
- Python help()用法及代碼示例
- Python NumPy hstack方法用法及代碼示例
- Python BeautifulSoup has_attr方法用法及代碼示例
- Python hasattr方法用法及代碼示例
- Python http.HTTPStatus用法及代碼示例
- Python hashlib.sha3_512()用法及代碼示例
- Python help方法用法及代碼示例
- Python hashlib.shake_256()用法及代碼示例
- Python hashlib.shake_128()用法及代碼示例
- Python hashlib.blake2s()用法及代碼示例
- Python hashlib.blake2b()用法及代碼示例
- Python hasattr()用法及代碼示例
- Python html.escape()用法及代碼示例
- Python statistics harmonic_mean()用法及代碼示例
- Python html.unescape()用法及代碼示例
- Python hash()用法及代碼示例
- Python hashlib.sha3_224()用法及代碼示例
- Python hex方法用法及代碼示例
- Python hex()用法及代碼示例
- Python OpenCV haveImageReader()用法及代碼示例
- Python NumPy hsplit方法用法及代碼示例
- Python http.client.HTTPConnection.set_tunnel用法及代碼示例
- Python NumPy histogram方法用法及代碼示例
注:本文由純淨天空篩選整理自Isshin Inada大神的英文原創作品 NumPy | hypot method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。