title: How to get rid of "RuntimeWarning: invalid value encountered in greater"
body: <p>This question is very similar to a lot of questions related with the warning <code>RuntimeWarning: invalid value encountered in greater/less/etc</code></p>
  
  <p>However, I couldn't find a solution for my particular problem, and I think there should be one.</p>
  
  <p>So, I have a <code>numpy.ndarray</code> similar to this one:</p>
  
  <pre><code>array([[ nan,   1.,  nan, ...,  nan,  nan,  nan],
         [ nan,  nan,  nan, ...,  nan,  nan,  nan],
         [ nan,  nan,  nan, ...,  nan,  nan,  nan],
         ..., 
         [ nan,  nan,  nan, ...,  nan,  nan,  nan],
         [ nan,  nan,  nan, ...,  nan,  nan,  nan],
         [ nan,  nan,  nan, ...,  nan,  nan,  nan]])
  </code></pre>
  
  <p>I want to calculate <code>array &gt; 0.5</code>, which gives exactly the result I want, but with the warning for being comparing with <code>nan</code>:</p>
  
  <pre><code>__main__:1: RuntimeWarning: invalid value encountered in greater
  Out[68]: 
  array([[False,  True, False, ..., False, False, False],
         [False, False, False, ..., False, False, False],
         [False, False, False, ..., False, False, False],
         ..., 
         [False, False, False, ..., False, False, False],
         [False, False, False, ..., False, False, False],
         [False, False, False, ..., False, False, False]], dtype=bool)
  </code></pre>
  
  <p>I basically want to calculate <code>array &gt; 0.5</code>, but without the warning showing up. </p>
  
  <p>My restrictions:</p>
  
  <ul>
  <li>I do <strong>NOT</strong> want to just suppress the warning with <code>with np.errstate(invalid='ignore'):</code></li>
  <li>I need to maintain the original array, thus I cannot change it.</li>
  </ul>
  
  <p>I have come up with a simple solution:</p>
  
  <ul>
  <li>Change the <code>nan</code> in the original matrix (<code>array[np.isnan(array)] = -np.inf</code>), recovering it back after I do my comparison (<code>array[array == -np.inf] = np.nan</code>)</li>
  </ul>
  
  <p>But I think it is just a waste of time all these calculations when (I think) it should exist a direct way to do this at once. I have been exploring the <code>numpy.ma</code> module and the <code>numpy.where</code> function, but I couldn't find this "direct" solution which I want.</p>
  
  <p>Any thoughts on this?</p>