python normal distribution
<p>I have a list of numbers, with sample mean and SD for these numbers. Right now I am trying to find out the numbers out of mean+-SD,mean +-2SD and mean +-3SD.
For example, in the part of mean+-SD, i made the code like this:</p>

<pre><code>ND1 = [np.mean(l)+np.std(l,ddof=1)]    
ND2 = [np.mean(l)-np.std(l,ddof=1)]

m=sorted(l)

print(m)

ND68 = []

if ND2 &gt; m and m&lt; ND1:

    ND68.append(m&lt;ND2 and m&gt;ND1)
    print (ND68)
</code></pre>

<p>Here is my question:
1. Could number be calculated by the list and arrange. If so, which part I am doing wrong.  Or there is some package I can use to solve this.</p>

<p>This might help.  We will use <code>numpy</code> to grab the values you are looking for.  In my example, I create a normally distributed array and then use boolean slicing to return the elements that are outside of +/- 1, 2, or 3 standard deviations.  </p>

<pre><code>import numpy as np

# create a random normally distributed integer array
my_array = np.random.normal(loc=30, scale=10, size=100).astype(int)

# find the mean and standard dev
my_mean = my_array.mean()
my_std = my_array.std()

# find numbers outside of 1, 2, and 3 standard dev
# the portion inside the square brackets returns an
# array of True and False values.  Slicing my_array
# with the boolean array return only the values that
# are True
out_std_1 = my_array[np.abs(my_array-my_mean) &gt; my_std]
out_std_2 = my_array[np.abs(my_array-my_mean) &gt; 2*my_std]
out_std_3 = my_array[np.abs(my_array-my_mean) &gt; 3*my_std]
</code></pre>

python python-3.x