简体   繁体   English

Python-EXP中遇到的溢出

[英]Python - overflow encountered in exp

I am using a formula in a model I'm developing, which, when it runs produces RuntTimeWarning: overflow encountered in exp. 我正在开发的模型中使用公式,该公式运行时会产生RuntTimeWarning:exp中遇到溢出。 My understanding from what I've read is that this due to excessively large numbers being used in the calculation for the data type. 根据我的阅读,我的理解是这是由于在数据类型的计算中使用了过多的数字。

My formula stores to a numpy array, so is there a method for changing the datatype so that these values can be computed? 我的公式存储到numpy数组中,是否有一种方法可以更改数据类型以便可以计算这些值?

Thanks 谢谢

This sounds like an XY problem . 这听起来像是XY问题

While higher precision datatypes could possibly solve this issue, this often comes at a performance and usability cost. 尽管更高精度的数据类型可能可以解决此问题,但这通常是以性能和可用性为代价的。 This is not possible with numpy directly, but can be done with mpmath. 直接使用numpy无法做到这一点,但可以使用mpmath完成。 More details can be found in this question . 在这个问题中可以找到更多细节。

Before resorting to such measures: 在采取此类措施之前:

  1. Verify that these large numbers are actually correct behavior and do not result from a bug further up. 验证这些大量数字实际上是正确的行为,并且不是由进一步的错误导致的。

  2. See if it is possible to log-transform your formulas so that large numbers are avoided. 查看是否可以对公式进行对数转换,从而避免使用大量的公式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM