[英]Equivalent of the Matlab function `eps` in Python/Numpy
In Matlab eps
has the following feature:在 Matlab 中eps
具有以下特点:
d = eps(x), where x has data type single or double, returns the positive distance from abs(x) to the next larger floating-point number of the same precision as x. d = eps(x),其中 x 的数据类型为 single 或 double,返回从 abs(x) 到下一个与 x 精度相同的较大浮点数的正距离。
What is the equivalent way of computing this in Python or Numpy?在 Python 或 Numpy 中计算这个的等效方法是什么?
When searching for the answer, I found references to np.finfo(np.float64).eps
, which is only the equivalent of eps('double')
in Matlab.在寻找答案时,我找到了对np.finfo(np.float64).eps
引用,它仅相当于 Matlab 中的eps('double')
。
You might be searching for numpy spacing .您可能正在寻找numpy 间距。 Here an example:这里有一个例子:
import numpy as np
for i in [1e-2, 1, 1e5, 1e10]:
print(f'Spacing for {i:.4e} :\t {np.spacing(i):.4e}')
And here the output:这里的输出:
Spacing for 1.0000e-02 : 1.7347e-18
Spacing for 1.0000e+00 : 2.2204e-16
Spacing for 1.0000e+05 : 1.4552e-11
Spacing for 1.0000e+10 : 1.9073e-06
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.