Overflow in exp in scipy/numpy in Python?

前端 未结 5 1700
谎友^
谎友^ 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:25

    In your case, it means that b is very small somewhere in your array, and you're getting a number (a/b or exp(log(a) - log(b))) that is too large for whatever dtype (float32, float64, etc) the array you're using to store the output is.

    Numpy can be configured to

    1. Ignore these sorts of errors,
    2. Print the error, but not raise a warning to stop the execution (the default)
    3. Log the error,
    4. Raise a warning
    5. Raise an error
    6. Call a user-defined function

    See numpy.seterr to control how it handles having under/overflows, etc in floating point arrays.

提交回复
热议问题