summaryrefslogtreecommitdiff
path: root/numpy/lib/function_base.py
diff options
context:
space:
mode:
authorDavid Freese <dfreese@stanford.edu>2018-02-25 20:09:15 -0800
committerDavid Freese <dfreese@stanford.edu>2018-02-25 21:13:22 -0800
commit018dfbcaa69d8bcda4d909be11a65a188cf5d1dd (patch)
treecff8ab89c725708e8d9f3fa5632bbf4de6778188 /numpy/lib/function_base.py
parent1ee1a4ac7f79e8c707c416f81f049fd3ac94f1e6 (diff)
downloadnumpy-018dfbcaa69d8bcda4d909be11a65a188cf5d1dd.tar.gz
BUG: fix complex casting error in cov with aweights
When using cov with a complex input and with aweights specified, cov will error as a result of trying to cast a complex value into a float64. This comes about since average is used to calculate the sum of the weights from aweights. average returns the sum of weights as the same type as its result, not the weights type. For a complex input m, and any type for aweights, this would result in a complex value for fact. It appears the primary purpose of np.float64(fact) is to provide a NaN value from the divide when fact is an integer zero. This has been replaced by using numpy.divide to replicate the same behavior, but to also handle complex types.
Diffstat (limited to 'numpy/lib/function_base.py')
-rw-r--r--numpy/lib/function_base.py2
1 files changed, 1 insertions, 1 deletions
diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py
index 391c47a06..e1e6242ae 100644
--- a/numpy/lib/function_base.py
+++ b/numpy/lib/function_base.py
@@ -2309,7 +2309,7 @@ def cov(m, y=None, rowvar=True, bias=False, ddof=None, fweights=None,
else:
X_T = (X*w).T
c = dot(X, X_T.conj())
- c *= 1. / np.float64(fact)
+ c *= np.true_divide(1, fact)
return c.squeeze()