title: IndexError: index 9 is out of bounds for axis 0 with size 8
body: <p>I would like to delete a Numpy Array element in a for loop if it exceedes my limits. If an element is out of limits and the numpy delete function deletes it, the end of the range of my for loop, n, decreases by 1. but inside the for loop it doesn't decrease and I get the following error. How can I remove elements from numpy array without breaking my for loop?</p>
  <p>IndexError: index 9 is out of bounds for axis 0 with size 8</p>
  <pre><code>n=9
  ucl=0 + (3 * 1/ np.sqrt(n))
  lcl=0 - (3 * 1/ np.sqrt(n))
  x=np.random.normal(0,1,size=n)
  for i in range(0,n):
    if (xbar[i]&gt;ucl) | (xbar[i]&lt;lcl):
      xbar=np.delete(xbar, i)
      n=n-1 
  </code></pre>