Python中的机器Epsilon [英] Machine Epsilon in Python

查看:177
本文介绍了Python中的机器Epsilon的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究的手册(我是新手)说:

A manual that I am currently studying (I am a newbie) says:

相差少于机器epsilon的数字在数值上是相同的"

"Numbers which differ by less than machine epsilon are numerically the same"

使用Python,可以通过键入获取用于浮点值的机器epsilon

With Python, machine epsilon for float values can be obtained by typing

eps = numpy.finfo(float).eps

现在,如果我检查

1 + eps/10 != 1

我得到假.

但是如果我检查

0.1 + eps/10 != 0.1

我得到了真.

如果我将eps除以100,则我后面的逻辑表达式变为False. 那么,机器ε如何工作? Python文档只是说

My latter logical expression turns to be False if I divide eps by 100. So, how does machine epsilon work? The Python documentation just says

最小的可表示正数,例如1.0 + eps!=1.0.eps类型是适当的浮点类型."

"The smallest representable positive number such that 1.0 + eps != 1.0. Type of eps is an appropriate floating point type."

谢谢.

推荐答案

浮点数具有一定的精度,以科学计数法可以精确到小数点后几位.数字越大,表示中的最低有效数字越大,因此可能有助于该数字的ε"越大.

Floating point numbers have a certain precision, to a few decimal places in scientific notation. The larger the number, the larger the least significant digit in that representation, and thus the larger the "epsilon" that could contribute to that number.

因此,epsilon相对于其添加的数字,实际上在您引用的文档中已说明:"...这样,1.0 + eps!= 1.0".如果参考"数小例如一个数量级,则eps也变小.

Thus, the epsilon is relative to the number it is added to, which is in fact stated in the documentation you cited: "... such that 1.0 + eps != 1.0". If the "reference" number is smaller by, e.g. one order of magnitude, then eps is smaller, too.

如果不是这种情况,您将无法计算出小于em的数字 (在我的情况下为2.2e-16).

If that was not the case, you could not calculate at all with numbers smaller than eps (2.2e-16 in my case).

这篇关于Python中的机器Epsilon的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆