Overflow in exp in scipy/numpy in Python?

前端 未结 5 1697
谎友^
谎友^ 2021-02-05 04:45

What does the following error:

Warning: overflow encountered in exp

in scipy/numpy using Python generally mean? I\'m computing a ratio in log

5条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-05 05:24

    Isn't exp(log(a) - log(b)) the same as exp(log(a/b)) which is the same as a/b?

    >>> from math import exp, log
    >>> exp(log(100) - log(10))
    10.000000000000002
    >>> exp(log(1000) - log(10))
    99.999999999999957
    

    2010-12-07: If this is so "some values in the array b are intentionally set to 0", then you are essentially dividing by 0. That sounds like a problem.

提交回复
热议问题