numpy.power()和math.pow()不会给出相同的结果

far*_*awa 3 python math numpy floating-point-precision

numpy.power()是否比math.pow()更准确?

例:

特定 A = numpy.array([6.66655333e+12,6.66658000e+12,6.66660667e+12,3.36664533e+12])

我定义 result = numpy.power(A,2.5)

所以 >> result = [ 1.14750185e+32 1.14751333e+32 1.14752480e+32 2.07966517e+31]

然而:

math.pow(A[0],2.5) = 1.14750185103e+32

math.pow(A[1],2.5) = 1.14751332619e+32

math.pow(A[2],2.5) = 1.14752480144e+32

math.pow(A[3],2.5) = 2.079665167e+31

Mik*_*ler 6

这只是一个问题如何显示数字:

>>> result[0]
1.1475018493845227e+32
Run Code Online (Sandbox Code Playgroud)

和:

>>> math.pow(A[0],2.5)
1.1475018493845227e+32
Run Code Online (Sandbox Code Playgroud)

两种方式都导致相同的价值:

>>> result[0] == math.pow(A[0],2.5)
True
Run Code Online (Sandbox Code Playgroud)

result有自己的方法__repr__(),显示的数字不同于标准Python __repr__()float.