Search code examples
pythonnumpyoverflowexp

How to tell where my code gives an exp overflow, in numpy?


I keep getting this error when using numpy:

Warning (from warnings module):
  File "somepath.py", line 249
    return 1 / ( 1 + np.exp( -x))
RuntimeWarning: overflow encountered in exp

However this doesn't tell me anything, as I still have no idea how it got to this error. Usually when I get an error it traces back through the functions it went through to get to the error, but not with exp overflow.

How do I get an error in which it does show me this?


Solution

  • You can ask Python to turn the warning into an error:

    import warnings    
    warnings.filterwarnings("error", category=RuntimeWarning)
    

    (Docs)