From a73b09c186f5c6c2213b2cd60cfadf41d4900e04 Mon Sep 17 00:00:00 2001 From: Roman Zeyde Date: Thu, 19 Feb 2015 15:20:25 +0200 Subject: [PATCH] dsp: remove linalg.lstsq() dependency --- amodem/dsp.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/amodem/dsp.py b/amodem/dsp.py index 3adc0af..ce789c5 100644 --- a/amodem/dsp.py +++ b/amodem/dsp.py @@ -1,5 +1,4 @@ import numpy as np -from numpy import linalg from . import common @@ -64,9 +63,12 @@ def linear_regression(x, y): ''' Find (a,b) such that y = a*x + b. ''' x = np.array(x) y = np.array(y) - ones = np.ones(len(x)) - M = np.array([x, ones]).T - a, b = linalg.lstsq(M, y)[0] + mean_x = np.mean(x) + mean_y = np.mean(y) + x_ = x - mean_x + y_ = y - mean_y + a = np.dot(y_, x_) / np.dot(x_, x_) + b = mean_y - a * mean_x return a, b