求平滑值的方法實現(xiàn)起來非常簡單??
typealias T = Double
func smooth(input x:[T],weight a:T)->[T]{
var temp = [x[0]]
for i in 1..<x.count{
temp.append(a * x[i] + (1-a) * temp[i-1])
}
return temp
}
調用一次就是一階,一階結果當輸入出來就是二階。
定義一個關聯(lián)類型吧。省的哪天輸入數(shù)據(jù)是Float。