title: Replace numpy subarray when element matches a condition
body: <p>I have an <code>n x m x 3</code> numpy array. This represents a middle-step towards an RGB representation of a complex-function plotter. When the function being plotted takes infinite values or has singularities, parts of the RGB data become NaNs.</p>
  
  <p>I'm looking for an efficient way to replace a row containing a NaN with a row of my choice, perhaps <code>[0, 0, 0]</code> or <code>[1, 1, 1]</code>. In terms of the RGB values, this has the effect of replacing poorly-behaving pixels with white or black pixels. By <em>efficient</em>, I mean some way that takes advantage of numpy's vectorization and speed.</p>
  
  <p>Please note that I am not looking to merely replace the NaN values with 0 (which I know how to do with <code>numpy.where</code>); if a row contains a NaN, I want to replace the whole row. I suspect this can be done nicely in numpy, but I'm not sure how.</p>
  
  <h2>Concrete Question</h2>
  
  <p>Suppose we are given a <code>2 x 2 x 3</code> array <code>arr</code>. If a row contains a 5, I want to replace the row with <code>[0, 0, 0]</code>. Trivial code that does this slowly is as follows.</p>
  
  <pre class="lang-py prettyprint-override"><code>import numpy as np
  
  arr = np.array([[[1, 2, 3], [4, 5, 6]], [[1, 3, 5], [2, 4, 6]]])
  
  # so arr is
  # array([[[1, 2, 3],
  #       [4, 5, 6]],
  #
  #       [[1, 3, 5],
  #        [2, 4, 6]]])
  
  # Trivial and slow version to replace rows containing 5 with [0,0,0]
  for i in range(len(arr)):
      for j in range(len(arr[i])):
          if 5 in arr[i][j]:
              arr[i][j] = np.array([0, 0, 0])
  
  # Now arr is
  #
  # array([[[1, 2, 3],
  #        [0, 0, 0]],
  #
  #       [[0, 0, 0],
  #        [2, 4, 6]]])
  </code></pre>
  
  <p>How can we accomplish this taking advantage of numpy?</p>