title: Exp function overflows and type casting does not work
body: <p>I keep getting this error for sigmoid function</p>
  
  <pre><code>RuntimeWarning: overflow encountered in exp
    return 1 / (1 + np.exp(-s))
  
  def sigmoid(s):
      return 1 / (1 + np.exp(-s))
  </code></pre>
  
  <p>I tried fixing it as follows inspired by <a href="https://stackoverflow.com/questions/40726490/overflow-error-in-pythons-numpy-exp-function">this</a> answer:</p>
  
  <pre><code>def sigmoid(s):
     s = s.astype(np.float128)
     min_value = np.finfo(s.dtype).min
     max_value = np.finfo(s.dtype).max
     s[s == np.NINF] = min_value
     s[s == np.inf] = max_value
     return 1 / (1 + np.exp(-s))
  </code></pre>
  
  <p>But this does no effect and I still get the same error, why is it the case?
  Thanks</p>