Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0cfa4ed

Browse files
committed
Merge pull request numpy#3866 from charris/refactor-1.9-nanfunctions
Refactor 1.9 nanfunctions
2 parents c2dc2cd + 2f77e1e commit 0cfa4ed

File tree

4 files changed

+354
-212
lines changed

4 files changed

+354
-212
lines changed

numpy/core/_methods.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,9 @@ def _var(a, axis=None, dtype=None, out=None, ddof=0, keepdims=False):
9191
arrmean = arrmean.dtype.type(arrmean / rcount)
9292

9393
# Compute sum of squared deviations from mean
94-
# Note that x may not be inexact
95-
x = arr - arrmean
94+
# Note that x may not be inexact and that we need it to be an array,
95+
# not a scalar.
96+
x = asanyarray(arr - arrmean)
9697
if issubclass(arr.dtype.type, nt.complexfloating):
9798
x = um.multiply(x, um.conjugate(x), out=x).real
9899
else:

numpy/core/tests/test_numeric.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1473,6 +1473,10 @@ def test_basic(self):
14731473
assert_almost_equal(var(self.A), self.real_var)
14741474
assert_almost_equal(std(self.A)**2, self.real_var)
14751475

1476+
def test_scalars(self):
1477+
assert_equal(var(1), 0)
1478+
assert_equal(std(1), 0)
1479+
14761480
def test_ddof1(self):
14771481
assert_almost_equal(var(self.A, ddof=1),
14781482
self.real_var*len(self.A)/float(len(self.A)-1))
@@ -1492,6 +1496,10 @@ def test_basic(self):
14921496
assert_almost_equal(var(A), real_var)
14931497
assert_almost_equal(std(A)**2, real_var)
14941498

1499+
def test_scalars(self):
1500+
assert_equal(var(1j), 0)
1501+
assert_equal(std(1j), 0)
1502+
14951503

14961504
class TestCreationFuncs(TestCase):
14971505
#Test ones, zeros, empty and filled

0 commit comments

Comments
 (0)