python中epsilon什么意思,Python中的机器Epsilon

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

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

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

eps = numpy.finfo(float).eps

Now, If I check

1 + eps/10 != 1

I obtain False.

But If I check

0.1 + eps/10 != 0.1

I obtain True.

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

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

Thank you in advance.

解决方案

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.

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.

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值