gpt4 book ai didi

python - numpy 如何计算指数?

转载 作者:行者123 更新时间:2023-12-02 20:11:49 25 4
gpt4 key购买 nike

阅读后this question ,我想知道调用 np.exp 时会发生什么:用于导出返回数组中的值的数学/数字例程是什么?例如,我认为要计算 np.sqrt(x),可以使用牛顿法找到 y 到 y ** 2 - x = 0 的解。

(np.exp 的文档字符串没有说​​明这是如何完成的)

最佳答案

(稍微更新以更正原始链接线集,并为最初链接的线添加一个单独的线集:)numpy 绑定(bind)到 the C library implementation of exp ,使用a self-defined proxy if the appropriate-precision C99 variant is not available 。它的性能将取决于库的性能。

我不是数值算法方面的专家,但这两个 StackOverflow 问题看起来有很好的答案:Efficient implementation of natural logarithm (ln) and exponentiationFastest Implementation of Exponential Function Using SSE 。请注意the accepted answer to the first question (建议使用简单的泰勒展开)在实践中没有使用;相反,如 this answer suggests ,我们发现polynomial expansions for particular ranges, and add range reduction and subsequent correction, in real implementations .

另请参阅Python source code for math exponent function?this paper by Sushant Sachdeva and Nisheeth K. Vishnoi 。更多请参见Google Search .

关于python - numpy 如何计算指数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53419270/

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