numpy.power() 和 math.pow() 不会给出相同的结果
numpy.power() and math.pow() don't give the same result
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
这只是一个数字如何显示的问题:
>>> result[0]
1.1475018493845227e+32
和:
>>> math.pow(A[0],2.5)
1.1475018493845227e+32
两种方式都导致相同的值:
>>> result[0] == math.pow(A[0],2.5)
True
result
有自己的方法 __repr__()
,它显示数字的方式与 float
.
的标准 Python __repr__()
不同
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
这只是一个数字如何显示的问题:
>>> result[0]
1.1475018493845227e+32
和:
>>> math.pow(A[0],2.5)
1.1475018493845227e+32
两种方式都导致相同的值:
>>> result[0] == math.pow(A[0],2.5)
True
result
有自己的方法 __repr__()
,它显示数字的方式与 float
.
__repr__()
不同