def detrend_linear(y):
 x = np.arange(len(y), dtype=np.float_)
 C = np.cov(x, y, bias=1)
 b = (C[(0, 1)] / C[(0, 0)])
 a = (y.mean() - (b * x.mean()))
 return (y - ((b * x) + a))

def detrend_linear ( y ) : x = np . arange ( len ( y ) , dtype = np . float_ ) C = np . cov ( x , y , bias = 1 ) b = ( C [ ( 0 , 1 ) ] / C [ ( 0 , 0 ) ] ) a = ( y . mean ( ) - ( b * x . mean ( ) ) ) return ( y - ( ( b * x ) + a ) )
return y minus best fit line; linear detrending .