为单精度和双精度浮点运算找到机器的epsilon。
我已经使用以下代码完成了双精度,但是在python中找不到单个精度epsilon值虽然在c ++中它出来是5:960464 * 10 ** - 8
import sys
import numpy as np
epsilon=sys.float_info.epsilon/2.0
#Using the System Info, in python float is taken as double precision automatically
print("Value of Machine epsilon double Precision is:",epsilon)
epsilon1 =1.0 #Using the while Loop, we see both values comes out to be same
while(1+epsilon1!=1):
epsilon1 = epsilon1*0.5
print("Value of Machine epsilon double Precision is:",epsilon1)
答案 0 :(得分:1)
您可以使用:
np.finfo(np.float32).eps