# 範例一

``````>>> x = [1,2,3,4,5]
>>> mean(x)
3.0
>>> x=[1,2,3,4,5,6]
>>> mean(x)
3.5
>>> sum(x)/6
3.5```
```

# 範例二

``````>>> s = sp.randn(100)
>>> s
array([ 0.81846905, -0.206404  ,  0.04115042,  0.51684893,  0.16637882,
-0.73836188, -0.08306182, -0.58723059, -0.24179899,  1.04275659,
0.24947425, -0.82042454, -1.7403959 ,  0.19852693, -0.29634134,
0.46413926,  0.99778752, -1.1042843 ,  0.68394051,  0.61526696,
0.87677284,  0.4744107 ,  0.49778494, -0.37790903, -0.41810024,
-0.92315847, -0.29561186,  1.05319456, -0.82868375,  2.23941517,
-0.7016392 , -0.75365341,  0.3458369 , -1.09171746,  1.19271684,
0.07945535,  0.13771758,  1.15739852, -1.08806617, -0.7665826 ,
-1.29355613,  0.72018477, -0.49924081, -0.93643934, -1.00544145,
1.1118645 , -0.42965894,  0.879536  ,  0.40060254, -1.04417166,
0.77200148,  0.65680009,  0.61177494,  1.0622201 ,  1.29132315,
0.79713301,  0.3011474 ,  0.64205807, -0.96367853, -0.91645682,
0.17813906,  0.68752781,  0.35641676, -0.29888325,  1.2615063 ,
-0.25650754, -1.87887921, -1.28345256,  0.05882579,  1.49113695,
0.64879919, -1.04886286, -0.08680253, -1.02739249, -0.25119126,
-0.7218675 , -0.63581296, -0.61223376, -0.57580404, -1.20087052,
-0.01721705,  0.88722105, -1.65392975, -0.56155685, -1.07593906,
0.47305601, -0.31929999, -0.67340951,  0.49928351,  0.42550937,
-1.04867572, -0.4893241 ,  0.0611306 , -0.6252364 , -0.428681  ,
-0.31425925,  0.23643226,  0.00983502, -0.21713571,  1.28594723])
>>> s.mean()
-0.057984384797540277
>>> s.max()
2.2394151712752057
>>> s.min()
-1.87887921016916
>>> s.var()
0.66484939561623224
>>> s.std()
0.8153829748138185
>>> median(s)
-0.084932172153511315
>>> var(s)
0.66484939561623224
>>> var(s, ddof=1)
0.67156504607700229
>>> from scipy import stats
>>> stats.describe(s)
(100, (-1.87887921016916, 2.2394151712752057), -0.057984384797540277, 0.67156504607700229, 0.1199184494811838, -0.5524733472330245)
>>> n = stats.norm(loc=3.5, scale=2.0)
>>> n.rvs()
4.831272143178463
>>> n.rvs()
2.8861479633680927
>>> n.rvs(size=100)
array([ 2.11184939,  4.78165465,  4.12409628,  4.5026254 ,  3.43577725,
3.08707195,  1.08559378,  4.43936556, -0.08060345,  0.11254478,
3.97356158,  2.99724993,  4.3711152 ,  5.49200907,  5.13812998,
-0.33957203, -0.77464655, -0.27844991, -0.37933802,  1.28560726,
3.48797001,  4.16787746,  3.12217925,  4.21513224,  0.71591849,
3.8606024 ,  0.33783606,  2.47740255,  2.85838788,  0.03450961,
-0.6361362 ,  4.2122434 ,  0.06084516,  1.67969954,  3.31455011,
4.40255746,  3.50529632,  0.55936595,  1.66843076,  2.21574165,
2.14045843,  0.29911356,  3.98899147,  5.2209135 ,  3.09099967,
4.0916305 ,  3.6033646 ,  1.83276318,  1.35611439,  5.46559031,
6.73534857,  5.2327596 ,  4.60828241, -1.6882662 ,  5.57548435,
7.33423661,  0.88707396,  2.20646822,  4.44804549,  1.92187448,
1.20585576,  2.56594066,  5.25369073,  4.6100597 ,  1.7517909 ,
1.98021973, -0.84243018,  3.50121971,  4.51619849,  5.26074887,
-0.33572785,  5.37461601, -1.32558684,  2.10987711,  4.07143877,
4.88234816,  4.66115453,  5.56711906,  2.67081842,  4.36641944,
6.57944382,  0.45365671,  6.99858181,  3.60578627,  6.40016184,
5.77376511,  2.91588904,  3.41166583,  7.36777987,  0.78873316,
7.58259791,  3.96921519,  1.98166742,  1.07761526,  0.07161138,
-0.25385144,  2.02653839,  2.93447523,  3.65707149,  1.56364379])
>>> stats.norm.pdf(0, loc=0.0, scale=1.0)
0.3989422804014327
>>> stats.norm.pdf([-0.1, 0.0, 0.1], loc=0.0, scale=1.0)
array([ 0.39695255,  0.39894228,  0.39695255])
>>> tries = range(11)
>>> print(stats.binom.pmf(tries, 10, 0.5))
[ 0.00097656  0.00976563  0.04394531  0.1171875   0.20507813  0.24609375
0.20507813  0.1171875   0.04394531  0.00976563  0.00097656]
>>> def binom_pmf(n=4, p=0.5):
...     x = range(n+1)
...     y = stats.binom.pmf(x, n, p)
...     plt.plot(x,y,"o", color="black")
...     plt.axis([-(max(x)-min(x))*0.05, max(x)*1.05, -0.01, max(y)*1.10])
...     plt.xticks(x)
...     plt.title("Binomial distribution PMF for tries = {0} & p ={1}".format(n,p))
...     plt.xlabel("Variate")
...     plt.ylabel("Probability")
...     plt.draw()
...
>>> binom_pmf()
>>> binom_pmf()```
```