From 8b5a966c4e3fe4de4e5046057793fecf1ee2000e Mon Sep 17 00:00:00 2001 From: qc <949686345@qq.com> Date: Sun, 10 Dec 2017 16:40:59 +0800 Subject: [PATCH 1/2] add p13 and p65 --- Codes.python/P13/qc2.py | 13 +++++++++++++ Codes.python/P65/qc.py | 43 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) create mode 100644 Codes.python/P13/qc2.py create mode 100644 Codes.python/P65/qc.py diff --git a/Codes.python/P13/qc2.py b/Codes.python/P13/qc2.py new file mode 100644 index 0000000..af31d92 --- /dev/null +++ b/Codes.python/P13/qc2.py @@ -0,0 +1,13 @@ +import numpy as np +import math +narray=np.array([7, 38, 4, 23, 18]) +sum1=narray.sum() +narray2=narray*narray +sum2=narray2.sum() +mean=sum1/5 +var=sum2/5-mean**2 +sd=math.sqrt(var) +print("The Expectation / Mean is{:.2f}".format(mean)) +print("The Variance is:{:.2f}".format(var)) +print("The Standard Deviation is:{:.2f}".format(sd)) + diff --git a/Codes.python/P65/qc.py b/Codes.python/P65/qc.py new file mode 100644 index 0000000..5a2e896 --- /dev/null +++ b/Codes.python/P65/qc.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- + +import numpy as np +import matplotlib.pyplot as plt +import time +import os +#from threading import Thread + + + +pHead = np.arange(0, 1.01, 0.01) + +n = len(pHead) +H = np.zeros(n) + +for i in range(0, n): + p = [pHead[i], 1 - pHead[i]] + if pHead[i] == 0: + p = 1 - pHead[i] + elif 1 - pHead[i] == 0: + p = pHead[i] + #用np.round来控制精度 + p = np.round(p, decimals = 3) + H[i] = -np.sum(p * np.log2(p)) + #modify:修正0.3 % 0.1 = 0.099999999999999978这类python的bug,采用将小数转换为整数的方法 + if pHead[i] * 10 % 1 == 0 and pHead[i] != 0 and pHead[i] != 1: + plt.ylabel('Probability') + plt.ylim(0, 1) + plt.bar(left = (0, 1), height = (p[0], p[1]), width = 1, align='center') + plt.title('pHead={:.2f}, pTail={:.2f}'.format(pHead[i], 1 - pHead[i])) + plt.xticks((0, 1), ('pHead', 'pTail')) + dirpath = os.path.dirname(__file__) + plt.savefig(dirpath + '\pHead={:.2f}, pTail={:.2f}.png'.format(pHead[i], 1 - pHead[i])) + plt.show(block = False) + #plt.show() + #可自行控制时间 + time.sleep(3) + plt.close() + + + + + From 2997a429e50f0a9767b9175f461717074ea53c9e Mon Sep 17 00:00:00 2001 From: qc <949686345@qq.com> Date: Sun, 10 Dec 2017 16:44:47 +0800 Subject: [PATCH 2/2] modify readme --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index c0b2b44..c9ed277 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -The codes and slides for the first year graduate student course, the Fundamental of Mobile Robot. For best performance please open the slides with MS Powerpoint 2013 or higher +The codes and slides for the first year graduate student course, the Fundamental of Mobile Robot. For best performance please open the slides with MS Powerpoint 2013 or higher ## 学生更新记录: -- 霍煜豪 邮箱:591144810@qq.com 学号:201730310153。刚开始学python,改的比较慢到目前才改了16个,而且改的比较烂。。 +- 钱琛 邮箱:949686345@qq.com 学号:201730310117