pylab + random demo
来源:互联网 发布:淘宝网书籍杂志在哪找 编辑:程序博客网 时间:2024/05/20 11:31
#quote from 'introduction to computation and programming using python,# revised edition, MIT'import pylabimport randomdef flipPlot(minExp, maxExp): """Assumes minExp and maxExp positive integers; minExp < maxExp Plots results of 2**minExp to 2**maxExp coin flips""" ratios = [] diffs = [] xAxis = [] for exp in range(minExp, maxExp + 1): xAxis.append(2**exp) for numFlips in xAxis: numHeads = 0 for n in range(numFlips):#a single point on xAxis if random.random() < 0.5: numHeads += 1 numTails = numFlips - numHeads ratios.append(numHeads/float(numTails)) diffs.append(abs(numHeads - numTails)) pylab.title('Difference Between Heads and Tails') pylab.xlabel('Number of Flips') pylab.ylabel('Abs(#Heads - #Tails)') pylab.plot(xAxis, diffs) pylab.figure() pylab.title('Heads/Tails Ratios') pylab.xlabel('Number of Flips') pylab.ylabel('#Heads/#Tails') pylab.plot(xAxis, ratios) pylab.show() flipPlot(4, 20)
0 0
- pylab + random demo
- pylab demo
- another pylab demo
- random DEMO
- pylab
- pylab
- fortune random server demo
- random walk DEMO
- random随机数demo小游戏
- stanford cs106b random.h demo
- random generator demo(Law of Large Numbers)
- random
- Random();
- random
- Random
- Random
- random
- Random
- 灌南手机GPS卫星定位追踪找人
- 嵌入式产品电源设计
- [必藏]Android 最棒的开源集合库
- 淮安身份证号码户籍地址信息查询
- Python 主要模块和常用方法简览
- pylab + random demo
- 有关音频编码的知识与技术参数
- java.lang.IllegalArgumentException: error at ::0 can't find referenced pointcut
- HDU 2087 剪花布条
- HTML5新增主体标签
- 二叉排序树的删除
- 求2个数的最大公约数
- 初学Ext Js 5之一 -----Ext JS 5 的开发环境配置
- requirejs中非AMD规范js的加载