From cd212173210a59ff34aa4edd3308bc520ee3e974 Mon Sep 17 00:00:00 2001 From: Lars Buitinck Date: Mon, 5 Oct 2015 07:49:47 +0200 Subject: ENH: speed up cov by ~10% for large arrays MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replaces n² divisions by one division and n² multiplications. --- numpy/lib/function_base.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'numpy/lib/function_base.py') diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py index a0c9f1274..399e24fe8 100644 --- a/numpy/lib/function_base.py +++ b/numpy/lib/function_base.py @@ -2269,7 +2269,7 @@ def cov(m, y=None, rowvar=1, bias=0, ddof=None, fweights=None, aweights=None): # Determine the normalization if w is None: - fact = float(X.shape[1] - ddof) + fact = X.shape[1] - ddof elif ddof == 0: fact = w_sum elif aweights is None: @@ -2287,7 +2287,7 @@ def cov(m, y=None, rowvar=1, bias=0, ddof=None, fweights=None, aweights=None): else: X_T = (X*w).T c = dot(X, X_T.conj()) - c /= fact + c *= 1. / np.float64(fact) return c.squeeze() -- cgit v1.2.1