python学习——格拉布斯准则实现
生活随笔
收集整理的這篇文章主要介紹了
python学习——格拉布斯准则实现
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
python學習——格拉布斯準則實現自定義目錄標題
期末某課程設計有個題目要求用程序實現格拉布斯準則剔除異常數據,遂度娘,發現大神都是使用c++,java等解決問題,答主最近在學習python,遂現學現用,編了個還能用的python程序,用了一些數據檢驗還算靠譜。 // An highlighted block import math n=int(input('輸入樣本容量(3-20):')) r=input('選擇危險率(1.0%,2.0%,5.0%):') rr=int(r[0]) pmin=0.00 pmax=0.00 i=0 p=[] y=[] z=[] x=0.00 ss=0.00 samle=0 case=0 s3=[1.15,1.46,1.67,1.82,1.94,2.03,2.11,2.18,2.23,2.29,2.33,2.37,2.41,2.44,2.47,2.50,2.53,2.56] s2=[1.15,1.48,1.71,1.89,2.02,2.13,2.21,2.29,2.36,2.41,2.46,2.51,2.55,2.59,2.62,2.65,2.68,2.71] s1=[1.15,1.49,1.75,1.94,2.10,2.22,3.32,2.41,2.48,2.55,2.61,2.66,2.71,2.75,2.79,2.82,2.85,2.88] for i in range(0,n):p.insert(i,float(input('輸入數據:'))) def arevage(n,p):x=0.0for i in range(0, n):x += float(p[i]) / nreturn x def funcion(n,p):ss=0.0for i in range(0, n):ss += float((p[i]-arevage(n,p))**2) / (n - 1)return math.sqrt(ss) while samle!=-1:x=arevage(n,p)ss=funcion(n,p)pmin=min(p)pmax=max(p)if 2*x>pmin+pmax:t=float(x-pmin)/sssamle=0else :t=float(pmax-x)/sssamle=1if rr==1 :if t < s1[n - 3]:samle = -1breakelse:if samle==0:y.insert(0,pmin)p.remove(pmin)n=n-1else:y.insert(0,pmax)p.remove(pmax)n=n-1elif rr==2:if t < s2[n - 3]:samle = -1breakelse:if samle == 0:y.insert(0, pmin)p.remove(pmin)n=n-1else:y.insert(0, pmax)p.remove(pmax)n = n - 1elif rr==5:if t < s3[n - 3]:samle = -1breakelse:if samle == 0:y.insert(0, pmin)p.remove(pmin)n = n - 1else:y.insert(0, pmax)p.remove(pmax)n = n - 1 print("異常數據是:",y) print("正常數據是:",p)
總結
以上是生活随笔為你收集整理的python学习——格拉布斯准则实现的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 8 随机积分与随机微分方程
- 下一篇: 原生WebView长截图 和 Tence