2017-04-26 94 views
1

我不斷收到此錯誤使用numpy的時候:如何判斷我的代碼在numpy中給出exp溢出?

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

然而,這並沒有告訴我什麼,因爲我仍然不知道它是如何得到這個錯誤。通常,當我得到一個錯誤時,它通過函數追溯到錯誤,但不會使用exp溢出。

我該如何得到一個錯誤,它顯示了我這個?

+0

請參閱http://stackoverflow.com/questions/9559346/deal-with-overflow-in -exp-using-numpy – JkShaw

回答

2

你可以問Python來開啓警告插入錯誤:

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

Docs

+0

非常棒。謝謝 –

+0

不錯!不知道這個有用的功能... – MaxU