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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。