diff options
author | Lars Buitinck <larsmans@gmail.com> | 2015-10-05 07:49:47 +0200 |
---|---|---|
committer | Lars Buitinck <larsmans@gmail.com> | 2015-10-05 07:49:47 +0200 |
commit | cd212173210a59ff34aa4edd3308bc520ee3e974 (patch) | |
tree | 7ee2423aa916225438bbcb1997c72474931078f5 /numpy/lib/function_base.py | |
parent | 881849c5385524ceafc462d230960463a01e47a6 (diff) | |
download | numpy-cd212173210a59ff34aa4edd3308bc520ee3e974.tar.gz |
ENH: speed up cov by ~10% for large arrays
Replaces n² divisions by one division and n² multiplications.
Diffstat (limited to 'numpy/lib/function_base.py')
-rw-r--r-- | numpy/lib/function_base.py | 4 |
1 files changed, 2 insertions, 2 deletions
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() |