%pylab inline rcParams['figure.figsize'] = (10, 4) #wide graphs by default from __future__ import print_function from __future__ import division random.random(4) random.random( (4,4) ) mat = random.random((4,4)) sig = random.random(100) plot(sig) sig = (random.random(10000)*2) - 1 plot(sig) mean(sig) random.random(10000).mean() random.random(100000).mean() random.random(10000000).mean() randint(1, 7, 10) randint(1, 21, 10) randint(1, 7, 10).mean() randint(1, 7, 1000).mean() die_throws = randint(1, 7, 1000) from scipy.stats import mode mode(die_throws) 1000/6 sig = array ([13, 18, 13, 14, 13, 16, 14, 21, 13]) sig.mean() sig.median() mean(sig), median(sig) sort(sig) mode(sig) hist(sig); mode(sig) sig = r_[13, 18, 13, 14, 13, 16, 14, 21, 13, 18, 18, 18] mode(sig) normal() sig = normal(size=100) plot(sig) mat = normal(size=(128,128)) subplot(121) imshow(mat) colorbar() mat = random.random(size=(128,128)) subplot(122) imshow(mat) colorbar() #from numpy.random import * randint(1,7, 10) die = randint(1,7, 10) die hist(die) die = randint(1,7, 10) hist(die); hist(die, bins= (arange(7)+0.5)) die = randint(1,7, 100) hist(die, bins= (arange(7)+0.5)) die = randint(1,7, 10000) hist(die, bins= (arange(7)+0.5)); r = normal(size=10) hist(r); r = normal(size=100) hist(r); r = normal(0, 1, 10000) hist(r); hist(r, 31); r = normal(0, 5, 10000) hist(r, 31); hist(r); hist(r, 30); r = normal(0, 5, 10000) type(r) hist(r, 31) print(r.std(), r.var()) r = exponential(1, 10000) hist(r, 30); r = exponential(2, 10000) hist(r, 30); r = exponential(10, 10000) hist(r, 30); r = exponential(1, 10000) hist(r, 30); r = triangular(0,0, 5, 10000) hist(r); hist(r,30); r = triangular(left=1, mode=3, right=9, size=10000) hist(r); hist(r,31); r = gamma(1, 2, 10000) hist(r,30); r = gamma(5, 1, 10000) hist(r,30); r = gamma(50, 1, 10000) hist(r,30); r = poisson(0.5, 10000) hist(r,30); r = poisson(10, 10000) hist(r,30); binomial(1000, 1.0/6.0) 100.0/6 print(binomial(10000, 1.0/6.0)) r = binomial(10000, 1.0/6.0, 10000) hist(r,30); hist(sig); from scipy import stats quantiles = linspace(-0.5,1.5, 100) plot(quantiles, stats.uniform.pdf(quantiles)) ylim((0, 1.1)) quantiles = linspace(-4.5,4.5, 1024) plot(quantiles, stats.norm.pdf(quantiles)) ylim((0, 1.1)) quantiles = arange(50) plot(quantiles, stats.poisson.pmf(quantiles, 0.2), 'o-') plot(quantiles, stats.poisson.pmf(quantiles, 5), 'o-') plot(quantiles, stats.poisson.pmf(quantiles, 20), 'o-') legend(['$\lambda$ = 0.2','$\lambda$ = 5','$\lambda$ = 20'])