Overflow Error in Python's numpy.exp function

后端 未结 4 1533
囚心锁ツ
囚心锁ツ 2020-11-30 05:31

I want to use numpy.exp like this:

cc = np.array([
    [0.120,0.34,-1234.1]
])

print 1/(1+np.exp(-cc))

But this gives me erro

4条回答
  •  自闭症患者
    2020-11-30 05:38

    The largest value representable by a numpy float is 1.7976931348623157e+308, whose logarithm is about 709.782, so there is no way to represent np.exp(1234.1).

    In [1]: import numpy as np
    
    In [2]: np.finfo('d').max
    Out[2]: 1.7976931348623157e+308
    
    In [3]: np.log(_)
    Out[3]: 709.78271289338397
    
    In [4]: np.exp(709)
    Out[4]: 8.2184074615549724e+307
    
    In [5]: np.exp(710)
    /usr/local/bin/ipython:1: RuntimeWarning: overflow encountered in exp
      #!/usr/local/bin/python3.5
    Out[5]: inf
    

提交回复
热议问题