title: Replace list values above and below thresholds with default value in python?
body: <p>I am trying to replace "bad values" below and above of thresholds with a default value (e.g. setting them to NaN).
  I am unsing a numpy array with 1000k values and more - so performance is an issue. </p>
  
  <p>My prototype does the operation in two steps, is there a pssoibility to do this in one step?</p>
  
  <pre><code>import numpy as np
  
  data = np.array([0., 1., 2., 3., 4., 5., 6., 7., 8., 9.])
  
  upper_threshold = 7
  lower_threshold = 1
  default_value = np.NaN
  
  # is it possible to do this in one expression?
  data[data &gt; upper_threshold] = default_value
  data[data &lt; lower_threshold] = default_value
  
  print data # [ nan   1.   2.   3.   4.   5.   6.   7.  nan  nan]
  </code></pre>
  
  <p>As commented in this related question (<a href="https://stackoverflow.com/questions/41329691/pythonic-way-to-replace-list-values-with-upper-and-lower-bound-clipping">Pythonic way to replace list values with upper and lower bound (clamping, clipping, thresholding)?</a>)</p>
  
  <blockquote>
    <p>Like many other functions, np.clip is python, but it defers to arr.clip, the method. For regular arrays that method is compiled, so will be faster (about 2x). – hpaulj</p>
  </blockquote>
  
  <p>I hope to find a faster way too, thanks in advance!</p>