summaryrefslogtreecommitdiff
path: root/numpy/core/_methods.py
diff options
context:
space:
mode:
authorChirag Nighut <qawbecrdteyf@gmail.com>2019-04-01 19:19:09 +0530
committerMarten van Kerkwijk <mhvk@astro.utoronto.ca>2019-04-01 09:49:09 -0400
commitf297d317f9d2355228fb3a265e9ff3c69e37b1e2 (patch)
tree3be66954d69770fae88198a43d33ece44cde146b /numpy/core/_methods.py
parent51140bd0787127184f148cc6cc02a1196980f64e (diff)
downloadnumpy-f297d317f9d2355228fb3a265e9ff3c69e37b1e2.tar.gz
BUG: Fix of `var` method for complex object arrays
Previously, an object array which contained complex numbers would give complex output, as it was simply multiplied with itself instead of with its conjugate.
Diffstat (limited to 'numpy/core/_methods.py')
-rw-r--r--numpy/core/_methods.py7
1 files changed, 4 insertions, 3 deletions
diff --git a/numpy/core/_methods.py b/numpy/core/_methods.py
index 51362c761..953e7e1b8 100644
--- a/numpy/core/_methods.py
+++ b/numpy/core/_methods.py
@@ -115,10 +115,11 @@ def _var(a, axis=None, dtype=None, out=None, ddof=0, keepdims=False):
# Note that x may not be inexact and that we need it to be an array,
# not a scalar.
x = asanyarray(arr - arrmean)
- if issubclass(arr.dtype.type, nt.complexfloating):
- x = um.multiply(x, um.conjugate(x), out=x).real
- else:
+ if issubclass(arr.dtype.type, (nt.floating, nt.integer)):
x = um.multiply(x, x, out=x)
+ else:
+ x = um.multiply(x, um.conjugate(x), out=x).real
+
ret = umr_sum(x, axis, dtype, out, keepdims)
# Compute degrees of freedom and make sure it is not negative.