#==============================================================================
# 第2章 了解數(shù)據(jù) 15
# 2.1 簡(jiǎn)介 16
# 2.2 從CSV文件導(dǎo)入數(shù)據(jù) 16
#==============================================================================
#使用$head some_file.csv
import csv
filename = 'ch02-data.csv'
data = []
try:
#不必?fù)?dān)心在操作完資源之后去關(guān)閉數(shù)據(jù)文件,with語(yǔ)句的上下文管理器會(huì)幫助處理。
with open(filename) as f:
reader = csv.reader(f)
c = 0
for row in reader:
if c == 0:
header = row
else:
data.append(row)
c += 1
except csv.Error as e:
print "Error reading CSV file at line %s: %s" % (reader.line_num, e)
sys.exit(-1)
if header:
print header
print '=================='
for datarow in data:
print datarow
--------------------------------------------------------------------------
加載大數(shù)據(jù)文件,
import numpy
#速度較快
data=numpy.loadtxt('ch02-data.csv',dtype='string',delimiter=',')
for datarow in data:
print datarow
#更好的處理缺失數(shù)據(jù)
data=numpy.genfromtxt('ch02-data.csv',dtype='string',delimiter=',')
for datarow in data:
print datarow
#==============================================================================
# 2.3 從Microsoft Excel文件中導(dǎo)入數(shù)據(jù) 18
#==============================================================================
#讀寫(xiě)操作的支持是通過(guò)不同模塊實(shí)現(xiàn)的,跨平臺(tái)!
$ mkvirtualenv xlrdexample
(xlrdexample)$ pip install xlrd
#在指定工作簿中的工作表中,根據(jù)行數(shù)nrows和列數(shù)ncols讀取單元格的內(nèi)容:
#xlrd模塊按照需要,僅加載文件的部分內(nèi)容到內(nèi)存中
import xlrd
from xlrd.xldate import XLDateAmbiguous
file = 'ch02-xlsxdata.xlsx'
wb = xlrd.open_workbook(filename=file)
#
wb = xlrd.open_workbook(filename=file,on_demand=True)
ws = wb.sheet_by_name('Sheet1')
dataset = []
for r in ws.nrows:
col = []
for c in ws.ncols:
col.append(ws.cell(r, c).value)
#if ws.cell_type(r, c) == xlrd.XL_CELL_DATE:
# try:
# print ws.cell_type(r, c)
# from datetime import datetime
# date_value = xlrd.xldate_as_tuple(ws.cell(r, c).value, wb.datemode)
# print datetime(*date_value)
# except XLDateAmbiguous as e:
# print e
dataset.append(col)
#from pprint import pprint
#pprint(dataset)
#==============================================================================
# 2.4 從定寬數(shù)據(jù)文件導(dǎo)入數(shù)據(jù) 21
#==============================================================================
#性能更重要,或者要解析的文件非常大時(shí),使用Python中的struct模塊
import struct
import string
mask='9s14s5s'
parse = struct.Struct(mask).unpack_from
print 'formatstring {!r}, record size: {}'
.format(mask, struct.calcsize(mask))
datafile = 'ch02-fixed-width-1M.data'
with open(datafile, 'r') as f:
for line in f:
fields = parse(line)
print 'fields: ', [field.strip() for field in fields]
#==============================================================================
# 2.5 從制表符分隔的文件中讀取數(shù)據(jù) 23
#==============================================================================
"day"? "ammount"
2013-01-24? 323
2013-01-25? 233
2013-01-26? 433
2013-01-27? 555
2013-01-28? 123
2013-01-29? ? 0
2013-01-30? 221
import struct
import string
mask='9s14s5s'
parse = struct.Struct(mask).unpack_from
print 'formatstring {!r}, record size: {}' .format(mask, struct.calcsize(mask))
datafile = 'ch02-fixed-width-1M.data'
with open(datafile, 'r') as f:
for line in f:
fields = parse(line)
print 'fields: ', [field.strip() for field in fields]
------------------------------------------------------------------
"day"? "ammount"
2013-01-24? 323
2013-01-25? 233
2013-01-26? 433
2013-01-27? 555
2013-01-28? 123
? ? 2013-01-29? ? 0
2013-01-30? 221
datafile = 'ch02-data-dirty.tab'
with open(datafile, 'r') as f:
for line in f:
# remove next comment to see line before cleanup
# print 'DIRTY: ', line.split('\t')
# we remove any space in line start or end
line = line.strip()
# now we split the line by tab delimiter
print line.split('\t')?
------------------------------------------------------------------
#==============================================================================
# 2.6 從JSON數(shù)據(jù)源導(dǎo)入數(shù)據(jù) 24
#==============================================================================
$pip install requests
import requests
import json
url = 'https://github.com/timeline.json'
r = requests.get(url)
json_obj = r.json()
print json.dumps(json_obj,sort_keys=True,indent=4)
data1 = {'b':789,'c':456,'a':123}
print json.dumps(data1,sort_keys=True,indent=4)
=============================
1.對(duì)簡(jiǎn)單數(shù)據(jù)類型的encoding 和 decoding:
使用簡(jiǎn)單的json.dumps方法對(duì)簡(jiǎn)單數(shù)據(jù)類型進(jìn)行編碼.
在json的編碼過(guò)程中,會(huì)存在從python原始類型向json類型的轉(zhuǎn)化過(guò)程:
Python? -->>>>>---? JSON? -->>>>>--- Python?
dict object dict
list,tuple array list
str,unicode string unicode
int,long,float number (int) int,long
number (real) float
True true True
False false Flase
None null None
#coding=utf-8
import json
from decimal import Decimal
obj = [[1,2,3],123,123.123,'abc',{'key1':(1,2,3),'key2':(4,5,6)}]
encodedjson = json.dumps(obj)
print repr(obj)
print encodedjson
#[[1, 2, 3], 123, 123.123, 'abc', {'key2': (4, 5, 6), 'key1': (1, 2, 3)}]
#[[1, 2, 3], 123, 123.123, "abc", {"key2": [4, 5, 6], "key1": [1, 2, 3]}]
------------------------------------------------------------------------------
json.dumps方法提供了很多好用的參數(shù)可供選擇,
比較常用的有sort_keys(對(duì)dict對(duì)象進(jìn)行排序,我們知道默認(rèn)dict是無(wú)序存放的),
separators,indent等參數(shù)。
data1 = {'b':789,'c':456,'a':123}
data2 = {'a':123,'b':789,'c':456}
d1 = json.dumps(data1,sort_keys=True)
print d1 #{"a": 123, "b": 789, "c": 456}
d2 = json.dumps(data2)
print d2 #{"a": 123, "c": 456, "b": 789}
d3 = json.dumps(data2,sort_keys=True)
print d3 #{"a": 123, "b": 789, "c": 456}
print d1==d2 False
print d1==d3 True
#indent參數(shù)是縮進(jìn)的意思,它可以使得數(shù)據(jù)存儲(chǔ)的格式變得更加優(yōu)雅。
print json.dumps(data1,sort_keys=True,indent=4)
#{
#? ? "a": 123,
#? ? "b": 789,
#? ? "c": 456
#}
------------------------------------------------------------------------
loads方法返回了原始的對(duì)象,但是仍然發(fā)生了一些數(shù)據(jù)類型的轉(zhuǎn)化。例‘a(chǎn)bc’轉(zhuǎn)化為了unicode類型
decodejson = json.loads(encodedjson)
print type(decodejson)
print decodejson[4]['key1']
print decodejson
#<type 'list'>
#[1, 2, 3]
#[[1, 2, 3], 123, 123.123, u'abc', {u'key2': (4, 5, 6), u'key1': (1, 2, 3)}]
jstring='{"name":"xue","price":12.50}'
decodejson=json.loads(jstring,parse_float=Decimal)
print decodejson
#{u'price':Decimal(12.50),u'name':u'xue'}
------------------------------------------------------------------------
json主要是作為一種數(shù)據(jù)通信的格式存在的,
而網(wǎng)絡(luò)通信是很在乎數(shù)據(jù)的大小的,無(wú)用的空格會(huì)占據(jù)很多通信帶寬,所以適當(dāng)時(shí)候也要對(duì)數(shù)據(jù)進(jìn)行壓縮。
separator參數(shù)可以起到這樣的作用,該參數(shù)傳遞是一個(gè)元組,包含分割對(duì)象的字符串。
#coding=utf-8
import json
data={'a': 123, 'c': 456, 'b': 789}
#DATA: {'a': 123, 'c': 456, 'b': 789}
print 'repr(data) :', len(repr(data))
#repr(data): 30
print 'dumps(data) :', len(json.dumps(data))
#dumps(data): 30
print 'dumps(data, indent=2):', len(json.dumps(data, indent=4))
#dumps(data, indent=2)? : 46
print 'dumps(data, separators):', len(json.dumps(data, separators=(',',':')))
#dumps(data, separators): 25
print json.dumps(data, separators=(',',':'))
#{"a":123,"c":456,"b":789}
------------------------------------------------------------------------
另一個(gè)比較有用的dumps參數(shù)是skipkeys,默認(rèn)為False。 dumps方法存儲(chǔ)dict對(duì)象時(shí),key必須是str類型,如果出現(xiàn)了其他類型的話,那么會(huì)產(chǎn)生TypeError異常,
如果開(kāi)啟該參數(shù),設(shè)為T(mén)rue的話,則會(huì)比較優(yōu)雅的過(guò)度。
data = {'b':789,'c':456,(1,2):123}
print json.dumps(data,skipkeys=True)
#{"c": 456, "b": 789}
------------------------------------------------------------------------
=======================
2.處理自己的數(shù)據(jù)類型
#方法二:繼承JSONEncoder和JSONDecoder類,覆寫(xiě)相關(guān)方法
import json
class Person(object):
def __init__(self,name,age):
self.name = name;
self.age = age;
def __repr__(self):
print (('Person Object name : %s , age:%d')%(self.name,self.age))
class MyEncoder(json.JSONEncoder):
def default(self,obj):
#convert object to a dict
d = {}
d['__class__'] = obj.__class__.__name__
d['__module__'] = obj.__module__
d.update(obj.__dict__)
return d
class MyDecoder(json.JSONDecoder):
def __init__(self):
json.JSONDecoder.__init__(self,object_hook=self.dict2object)
def dict2object(self,d):
#convert dict to object
if'__class__' in d:
class_name = d.pop('__class__')
module_name = d.pop('__module__')
module = __import__(module_name)
class_ = getattr(module,class_name)
args = dict((key.encode('ascii'), value) for key, value in d.items()) #get args
inst = class_(**args) #create new instance
else:
inst = d
return inst
if __name__ == '__main__':
p = Person('Peter',22)
p = Person('Peter',22)
#print p
d =MyEncoder().encode(p)
print d
o =MyDecoder().decode(d)
print? type(o)
#==============================================================================
# 2.7 導(dǎo)出數(shù)據(jù)到JSON、CSV和Excel 27
#==============================================================================
#Excel讀操作
pip install xlwt
def import_data(import_file):
? ? mask = '9s14s5s'
? ? data = []
? ? parse = struct.Struct(mask).unpack_from
? ? i =1
? ? with open(import_file, 'r') as f:
? ? ? ? for line in f:
? ? ? ? ? ? fields = parse(line)
? ? ? ? ? ? data.append(list([f.strip() for f in fields]))
? ? ? ? ? ? i=i+4
? ? ? ? ? ? if i >100:
? ? ? ? ? ? ? ? return data
? ? return data
-----------------------------------------------------------------
def write_data(data, export_format):
? ? if export_format == 'csv':
? ? ? ? return write_csv(data)
? ? elif export_format == 'json':
? ? ? ? return write_json(data)
? ? elif export_format == 'xlsx':
? ? ? ? return write_xlsx(data)
? ? else:
? ? ? ? raise Exception("Illegal format defined")
-----------------------------------------------------------------
def write_csv(data):
? ? writer = csv.writer(file('export_csv.csv', 'wb'))
? ? for row in data:
? ? ? ? writer.writerow(row)
? ? return "export_csv.csv"
-----------------------------------------------------------------
def write_json(data):
? ? with open("export_json.json", "a") as file_obj:
? ? ? ? file_obj.write(json.dumps(data))
? ? return "export_json.json"
-----------------------------------------------------------------
def write_xlsx(data):
? ? from xlwt import Workbook
? ? book = Workbook()
? ? sheet1 = book.add_sheet("Sheet 1")
? ? row = 0
? ? for line in data:
? ? ? ? col = 0
? ? ? ? for datum in line:
? ? ? ? ? ? sheet1.write(row, col, datum)
? ? ? ? ? ? col += 1
? ? ? ? row += 1
? ? ? ? # We have hard limit here of 65535 rows
? ? ? ? # that we are able to save in spreadsheet.
? ? ? ? if row > 65535:
? ? ? ? ? ? print >> sys.stderr, "Hit limit of # of rows in one sheet (65535)."
? ? ? ? ? ? break
? ? book.save("export_xlsx.xls")
? ? return "export_xlsx.xls"
#==============================================================================
# 2.8 從數(shù)據(jù)庫(kù)導(dǎo)入數(shù)據(jù) 31
#==============================================================================
$pip install sqlite3
import sqlite3
import sys
script_path = "/root/PycharmProjects/demo/world.sql"
db ='/root/PycharmProjects/demo/world.db'
# if DB is not defined ,create memory database
#db = ":memory:"
try:
con = sqlite3.connect(db)
with con:
cur = con.cursor()
with open(script_path,'rb') as f:
cur.executescript(f.read())
print("Finish")
except sqlite3.Error as err:
print "Error occured: %s" % err
-----------------------------------------------------------------
import sqlite3
import sys
db = "/root/PycharmProjects/demo/world.db"
try:
? ? con = sqlite3.connect(db)
? ? with con:
? ? ? ? cur = con.cursor()
? ? ? ? query = 'SELECT ID, Name, Population FROM City ORDER BY Population DESC LIMIT 1000'
? ? ? ? con.text_factory = str
? ? ? ? cur.execute(query)
? ? ? ? resultset = cur.fetchall()
? ? ? ? # extract column names
? ? ? ? col_names = [cn[0] for cn in cur.description]
? ? ? ? print "%10s %30s %10s" % tuple(col_names)
? ? ? ? print "="*(10+1+30+1+10)
? ? ? ? for row in resultset:
? ? ? ? ? ? print "%10s %30s %10s" % row
except sqlite3.Error as err:
? ? print "[ERROR]:", err
#==============================================================================
# 2.9 清理異常值 36
#==============================================================================
yum install libpng
pip install matplotlib
#==============================================================================
# 2.10 讀取大塊數(shù)據(jù)文件 42
#==============================================================================
#即使相當(dāng)大的文件也可輕松操作(按需加載)
with open(bigfile_path,'r') as bigfile:
for line in bigfile
#...
#按文件塊依次讀取,而不需要將整個(gè)文件讀取到內(nèi)存中
import sys
filename = "ch02-fixed-width-1M.data"
with open(filename, 'rb') as hugefile:
chunksize = 1000
readable = ''
# if you want to stop after certain number of blocks
# put condition in the while
while hugefile:
start = hugefile.tell()
for _ in range(start, start + chunksize):
file_block= hugefile.next()
print file_block
readable = readable + file_block
stop = hugefile.tell()
print ('readable? ? %s')%(readable)
print 'reading bytes from %s to %s' % (start, stop)
print 'read bytes total:', len(readable)
raw_input()
#大文件的讀取其他方案
#并行方法,如MapReduce
#多進(jìn)程處理,
#==============================================================================
# 2.11 讀取流數(shù)據(jù)源 44
#==============================================================================
##讀取一個(gè)實(shí)時(shí)變化的文件
#應(yīng)用:例如輸入是一個(gè)類文件對(duì)象或者一個(gè)遠(yuǎn)程HTTP資源,
#就可以從遠(yuǎn)程服務(wù)讀取輸入信息,并持續(xù)地解析它,然后實(shí)時(shí)地更新圖表,或者更新到中間隊(duì)列、緩沖或者數(shù)據(jù)庫(kù)
#在更為復(fù)雜的數(shù)據(jù)管道中,需要啟用消息隊(duì)列。達(dá)到的連續(xù)數(shù)據(jù)會(huì)被放在隊(duì)列里一段時(shí)間,然后才能被我們接收到。
import time
import os
import sys
with open('stream.data','r') as file:
? ? # Move to the end of file
? ? filesize = os.stat(filename)[6]
? ? file.seek(filesize)
? ? while True:
? ? ? ? where = file.tell()
? ? ? ? # try reading a line
? ? ? ? line = file.readline()
? ? ? ? # if empty, go back
? ? ? ? if not line:
? ? ? ? ? ? time.sleep(1)
? ? ? ? ? ? file.seek(where)
? ? ? ? else:
? ? ? ? ? ? # , at the end prevents print to add newline, as readline()
? ? ? ? ? ? # already read that.
? ? ? ? ? ? print line,
----------------------------------------------------------------------------
#coding=utf-8
#第一個(gè)用來(lái)讀取文件中的字節(jié)
def FileStream(filename):
? ? try:
? ? ? ? f = open(filename)
? ? ? ? for line in f:
? ? ? ? ? ? for byte in line:
? ? ? ? ? ? ? ? yield byte
? ? except StopIteration, e:
? ? ? ? f.close()
? ? ? ? return
#,第二個(gè)用來(lái)過(guò)濾流中的字節(jié),
def FilterStream(source, condition):
? ? try:
? ? ? ? while True:
? ? ? ? ? ? byte = source.next()
? ? ? ? ? ? if condition(byte):
? ? ? ? ? ? ? ? yield byte
? ? except StopIteration, e:
? ? ? ? return
#第三個(gè)將流進(jìn)的數(shù)據(jù)打印出來(lái)。
def PrintStream(source):
? ? try:
? ? ? ? while True:
? ? ? ? ? ? byte = source.next()
? ? ? ? ? ? print byte
? ? except StopIteration, e:
? ? ? ? return
PrintStream(FilterStream(FileStream('stream.data'), str.islower))
#==============================================================================
# 2.12 導(dǎo)入圖像數(shù)據(jù)到NumPy數(shù)組 46
#==============================================================================
$pip install? scipy
#############Lena圖
#SciPy將這幅圖打包在了misc模塊中,因此可以很簡(jiǎn)單的重用這幅圖
import scipy.misc
import matplotlib.pyplot as plt
lena = scipy.misc.lena()
plt.gray()
plt.imshow(lena)
plt.colorbar()
plt.show()
print lena.shape? ? ? ? #(512, 512)
print lena.max()? ? ? ? #245
print lena.dtype? ? ? ? #int32
##########PIL
pip install PIL --allow-external PIL --allow-unverified PIL
##########放大圖像
import matplotlib.pyplot as plt
import scipy
import numpy
# because the image we loaded is RGB image,
# http://en.wikipedia.org/wiki/Grayscale#Converting_color_to_grayscale
bug = scipy.misc.imread('stinkbug.png')
# if you want to inspect the shape of the loaded image
# uncomment following line
print bug.shape? ? #(375, 500, 3)
bug = bug[:,:,0]# convert to gray
# show original image
plt.figure()
plt.gray()
plt.subplot(121)
plt.imshow(bug)
# show 'zoomed' region
zbug = bug[100:350,140:350]#指定放大[100:350,140:350]之間的部分矩陣
plt.subplot(122)
plt.imshow(zbug)
plt.show()
###########對(duì)于大圖像推薦使用numpy.memmap來(lái)做圖像的內(nèi)存映射
import numpy
image=numpy.memmap('stinkbug.png', dtype=int, mode='r+',shape=(375,500))
#專注于圖像處理的專業(yè)軟件包
scikit-image:http://scikit-image.org/
#==============================================================================
# 2.13 生成可控的隨機(jī)數(shù)據(jù)集合 51
#==============================================================================
############生成一個(gè)簡(jiǎn)單的隨機(jī)數(shù)樣本
import pylab
import random
SAMPLE_SIZE = 100
random.seed() # seed random generator,if no argument provided,uses system current time
real_rand_vars = [] # store generated random values here
# we don't need iterator value, so we can put call it '_'
for _ in range(SAMPLE_SIZE):
? ? new_value = random.random() # get next random value
? ? real_rand_vars.append(new_value)
# create histogram from data in 10 buckets
pylab.hist(real_rand_vars, 10)
pylab.xlabel("Number range")
pylab.ylabel("Count")
# show figure
pylab.show()
############生成虛擬價(jià)格增長(zhǎng)數(shù)據(jù)的時(shí)序圖
import pylab
import random
# days to generate data for
duration = 100
mean_inc = 0.2 # mean value
std_dev_inc = 1.2 # standard deviation
x = range(duration) # time series
y = []
for i in x:
? ? next_delta = random.normalvariate(mean_inc, std_dev_inc)
? ? price_today += next_delta
? ? y.append(price_today)
pylab.plot(x,y)
pylab.xlabel("Time")
pylab.ylabel("Value")
pylab.show()
###################不同的分布顯示直方圖
# coding: utf-8
import random
import matplotlib
import matplotlib.pyplot as plt
SAMPLE_SIZE = 1000
buckets = 100# histogram buckets
plt.figure()
matplotlib.rcParams.update({'font.size': 7})# we need to update font size just for this example
###[0.0, 1.0)之間隨機(jī)分布
plt.subplot(621)
plt.xlabel("random.random")
res = []
for _ in xrange(1, SAMPLE_SIZE):res.append(random.random())
plt.hist(res, buckets)
###均勻分布[a,b]
plt.subplot(622)
plt.xlabel("random.uniform")
a = 1,b = SAMPLE_SIZE,res = []
for _ in xrange(1, SAMPLE_SIZE):res.append(random.uniform(a, b))
plt.hist(res, buckets)
###三角形分布
plt.subplot(623)
plt.xlabel("random.triangular")
low = 1, high = SAMPLE_SIZE, res = []
for _ in xrange(1, SAMPLE_SIZE):res.append(random.triangular(low, high))
plt.hist(res, buckets)
###beta分布
plt.subplot(624)
plt.xlabel("random.betavariate")
alpha = 1, beta = 10,res = []
for _ in xrange(1, SAMPLE_SIZE):res.append(random.betavariate(alpha, beta))
plt.hist(res, buckets)
###指數(shù)分布
plt.subplot(625)
plt.xlabel("random.expovariate")
lambd = 1.0 / ((SAMPLE_SIZE + 1) / 2.),res = []
for _ in xrange(1, SAMPLE_SIZE): res.append(random.expovariate(lambd))
plt.hist(res, buckets)
###gamma分布
# The probability distribution function is:
#Conditions on the parameters are alpha > 0 and beta > 0.
#? ? ? ? ? x ** (alpha - 1) * math.exp(-x / beta)
# pdf(x) =? --------------------------------------
#? ? ? ? ? ? math.gamma(alpha) * beta ** alpha
plt.subplot(626)
plt.xlabel("random.gammavariate")
alpha = 1,beta = 10,res = []
for _ in xrange(1, SAMPLE_SIZE):res.append(random.gammavariate(alpha, beta))
plt.hist(res, buckets)
###對(duì)數(shù)正態(tài)分布Log normal distribution。mu is the mean, and sigma is the standard deviation.
plt.subplot(627)
plt.xlabel("random.lognormvariate")
mu = 1,sigma = 0.5,res = []
for _ in xrange(1, SAMPLE_SIZE):res.append(random.lognormvariate(mu, sigma))
plt.hist(res, buckets)
###正態(tài)分布 Normal distribution. mu is the mean, and sigma is the standard deviation.
plt.subplot(628)
plt.xlabel("random.normalvariate")
mu = 1,sigma = 0.5,res = []
for _ in xrange(1, SAMPLE_SIZE):res.append(random.normalvariate(mu, sigma))
plt.hist(res, buckets)
###帕累托分布,Pareto distribution. alpha is the shape parameter.
plt.subplot(629)
plt.xlabel("random.paretovariate")
alpha = 1,res = []
for _ in xrange(1, SAMPLE_SIZE):res.append(random.paretovariate(alpha))
plt.hist(res, buckets)
plt.tight_layout()
plt.show()
###########隨機(jī)數(shù)
1)用seed初始化偽隨機(jī)數(shù)生成器,這樣random()方法就能生成相同的期望隨機(jī)值。
比較有用,比預(yù)先生成隨機(jī)數(shù)并保存到到文件中要好。
2)避免隨機(jī)生成的序列重復(fù),推薦使用random.SystemRandom,其底層使用os.urandom。
os.urandom提供更多熵源的訪問(wèn),seed()和setstate()沒(méi)有影響,則樣本不可重現(xiàn)了。
例子:想要一些隨機(jī)單詞
#Linux,針對(duì)Unix系統(tǒng)
import random
with open('/usr/share/dict/words') as f:
words=f.readlines()
words=[w.rstrip() for w in words]
for w in random.sample(words,5):
print w
#Windows
http://norvig.com/big.txt
#==============================================================================
# 2.14 真實(shí)數(shù)據(jù)的噪聲平滑處理 58
#==============================================================================