#NEWLINE# def moving_average( x , n , type = 'simple' ) : #NEWLINE# #INDENT# "\n    compute an n period moving average.\n    type is 'simple' | 'exponential'\n    " #NEWLINE# x = np . asarray ( x ) #NEWLINE# if ( type == 'simple' ) : #NEWLINE# #INDENT# weights = np . ones ( n ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# weights = np . exp ( np . linspace ( ( - 1.0 ) , 0.0 , n ) ) #NEWLINE# #UNINDENT# weights /= weights . sum ( ) #NEWLINE# a = np . convolve ( x , weights , mode = 'full' ) [ : len ( x ) ] #NEWLINE# a [ : n ] = a [ n ] #NEWLINE# return a