Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions Codes.python/P13/qc2.py
Original file line number Diff line number Diff line change
@@ -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))

43 changes: 43 additions & 0 deletions Codes.python/P65/qc.py
Original file line number Diff line number Diff line change
@@ -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()





4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -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