title: How to avoid an overflow in numpy.exp()
body: <p>I read a lot on stack Overflow but i still can't understand how avoiding the overflow error. I'am building a Neural network which use the <a href="https://en.wikipedia.org/wiki/Sigmoid_function" rel="nofollow noreferrer">sigmoid function</a>.
  But I cant go on without converting or finding a workaround for these errors.</p>
  
  <pre><code>def activation(x):
      return  1/(1+np.exp(-x))
  
    def dactivation(x):
      return  activation(x)*(1-activation(x))
  
  
    def propagateb(self, target, lrate=8.1, momentum=0.1):
          deltas = []
          error = target - self.layers[-1]
          delta = error*dactivation(self.layers[-1])
          deltas.append(delta)
          for i in range(len(self.shape)-2,0,-1):
              delta =np.dot(deltas[0],self.weights[i].T)*dactivation(self.layers[i])
              deltas.insert(0,delta)
          for i in range(len(self.weights)):
              layer = np.atleast_2d(self.layers[i])
              delta = np.atleast_2d(deltas[i])
              dw = np.dot(layer.T,delta)
              self.weights[i] += lrate*dw + momentum*self.dw[i]
              self.dw[i] = dw
  
          # Return error
          return (error**2).sum()
  </code></pre>
  
  <p>raise </p>
  
  <pre><code>ann.py:5: RuntimeWarning: overflow encountered in exp
    return  1/(1+np.exp(-x))
  </code></pre>