title: python: getting around division by zero
body: <p>I have a big data set of floating point numbers. I iterate through them and evaluate <code>np.log(x)</code> for each of them. 
  I get</p>
  
  <pre><code>RuntimeWarning: divide by zero encountered in log
  </code></pre>
  
  <p>I would like to get around this and return 0 if this error occurs.</p>
  
  <p>I am thinking of defining a new function:</p>
  
  <pre><code>def safe_ln(x):
      #returns: ln(x) but replaces -inf with 0
      l = np.log(x)
      #if l = -inf:
      l = 0
      return l
  </code></pre>
  
  <p>Basically,I need a way of testing that the output is <code>-inf</code> but I don't know how to proceed. 
  Thank you for your help!</p>