title: How to control and test "invalid value encountered in..." error?
body: <p>I have enountered a problem about <strong>invalid value...</strong> which is simple, but tricky in Python.
  How can I control or avoid this message by not loosing the meaning of the function(values) in large loops, for example, <code>+/-inf</code>, <code>nan</code>, etc?</p>
  
  <p>I put a test function as an example which is challenging me:</p>
  
  <pre><code>import numpy as np
  
  def test_func(t1, t2):
      return t1**t2
  
  def main():
      # test values
      t1 = np.array([0.0, 2., 1., -1., -.00000000000000000000021])
      t2 = np.array([0.0, 1.12, -3., -2., -.00000000000000000000021])
      print [test_func(i,j) for i in t1 for j in t2]
  
  if __name__ == '__main__':
      main()
  </code></pre>
  
  <p><strong>OUTPUT:</strong></p>
  
  <pre><code>Warning (from warnings module):
    File "__main__", line 2
  RuntimeWarning: divide by zero encountered in double_scalars
  
  Warning (from warnings module):
  File "__main__", line 2
  RuntimeWarning: invalid value encountered in double_scalars
  [1.0, 0.0, inf, inf, inf, 1.0, 2.1734697250521164, 0.125, 0.25, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, nan, -1.0, 1.0, nan, 1.0, nan, -1.079796998164345e+65, 2.2675736961451244e+43, nan]
  </code></pre>
  
  <p><strong>Additionally:</strong></p>
  
  <pre><code>RuntimeWarning: invalid value encountered in power
  </code></pre>
  
  <p>I read <strong>exception</strong> conditions, but I could not find the best way for the problem.</p>