[Haskell-cafe] Help to create a function to calculate a n element
moving average ??
rgowka1
rgowka1 at gmail.com
Sun Sep 26 12:20:58 EDT 2010
Type signature would be Int -> [Double] -> [(Double,Double)]
Any thoughts or ideas on how to calculate a n-element moving average
of a list of Doubles?
Let's say [1..10]::[Double]
what is the function to calculate the average of the 3 elements?
[(1,0),(2,0),(3,2),(4,3)....] :: [(Double,Double)]
(1,0) the average is zero as the length is less than 3
(2,0) the average is zero as the length is less than 3
(3,2) the average is (1+2+3)/3 = 2
(4,3) the average is (2+3+4)/3 = 9
......
More information about the Haskell-Cafe
mailing list