title: Fastest way to eleminate outlier in 2D array in python without pandas
body: <p>I need to iterate over a lot of itemsets and need to remove the outlier. As a threshold, I simply use the standard val &gt; 3* σ. Currently, I have the following solution:</p>
  <pre><code>def remove_outlier(data):
      data_t = np.array(data).T.tolist()
      
      for ele in data_t:
          temp = []
          for val in ele:
              if (val &lt; (3 * np.std(ele)) + np.mean(ele)) and (val &gt; (np.mean(ele) - 3 * np.std(ele))):
                  temp.append(val)
          data_t[i] = np.asarray(temp)
      data = np.asarray(data_t).T
      return data
  </code></pre>
  <p>I'm looking for a faster solution, because it takes up to 7 seconds per dataset (foreseeable for a double for-loop).</p>
  <p>I've come across scipy's <code>z-score</code> method and since it also supports the <code>axis=1</code> argument, it seems more valuable and faster than my solution. Is there a shortcut of how I can remove the corresponding z-scores from my dataset?
  I played around with <code>numpy.where()</code>, but it returns only certain values if compared above a threshold.</p>
  <p>The shape of the data is usually around <code>1000x8</code>, but can also be transposed without any problem.</p>