gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 13:41:32 28 4
gpt4 key购买 nike

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)

所以>> 结果 = [ 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

两种方式导致相同的值(value):

>>> result[0] == math.pow(A[0],2.5)
True

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

关于python - numpy.power() 和 math.pow() 不给出相同的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30286629/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com