summaryrefslogtreecommitdiff
path: root/numpy/ma
diff options
context:
space:
mode:
authorpierregm <pierregm@localhost>2010-04-27 16:55:09 +0000
committerpierregm <pierregm@localhost>2010-04-27 16:55:09 +0000
commit1e659b5ab591d47449b73481f2335a7a850495b7 (patch)
tree654bc5294ba7bcadd214383a6caad55508dc0009 /numpy/ma
parent56647963b940e56571ae9638e7c5f77ed58aadbb (diff)
downloadnumpy-1e659b5ab591d47449b73481f2335a7a850495b7.tar.gz
Fixed .var for arrays with 1 more valid value than ddofs
Diffstat (limited to 'numpy/ma')
-rw-r--r--numpy/ma/core.py2
-rw-r--r--numpy/ma/tests/test_core.py15
2 files changed, 15 insertions, 2 deletions
diff --git a/numpy/ma/core.py b/numpy/ma/core.py
index ff9fc4f4e..61c3a9761 100644
--- a/numpy/ma/core.py
+++ b/numpy/ma/core.py
@@ -4743,7 +4743,7 @@ class MaskedArray(ndarray):
dvar = divide(danom.sum(axis), cnt).view(type(self))
# Apply the mask if it's not a scalar
if dvar.ndim:
- dvar._mask = mask_or(self._mask.all(axis), (cnt <= ddof))
+ dvar._mask = mask_or(self._mask.all(axis), (cnt <= 0))
dvar._update_from(self)
elif getattr(dvar, '_mask', False):
# Make sure that masked is returned when the scalar is masked.
diff --git a/numpy/ma/tests/test_core.py b/numpy/ma/tests/test_core.py
index 014af2d73..f95d621db 100644
--- a/numpy/ma/tests/test_core.py
+++ b/numpy/ma/tests/test_core.py
@@ -199,7 +199,7 @@ class TestMaskedArray(TestCase):
err_status_ini = np.geterr()
try:
np.seterr(invalid='ignore')
- data = masked_array(np.sqrt([-1., 0., 1.]), mask=[0, 0, 1])
+ data = masked_array([np.nan, 0., 1.], mask=[0, 0, 1])
data_fixed = fix_invalid(data)
assert_equal(data_fixed._data, [data.fill_value, 0., 1.])
assert_equal(data_fixed._mask, [1., 0., 1.])
@@ -2707,6 +2707,19 @@ class TestMaskedArrayMathMethods(TestCase):
self.assertTrue(np.isnan(nout))
+ def test_varstd_ddof(self):
+ a = array([[1, 1, 0], [1, 1, 0]], mask=[[0, 0, 1], [0, 0, 1]])
+ test = a.std(axis=0, ddof=0)
+ assert_equal(test.filled(0), [0, 0, 0])
+ assert_equal(test.mask, [0, 0, 1])
+ test = a.std(axis=0, ddof=1)
+ assert_equal(test.filled(0), [0, 0, 0])
+ assert_equal(test.mask, [0, 0, 1])
+ test = a.std(axis=0, ddof=2)
+ assert_equal(test.filled(0), [0, 0, 0])
+ assert_equal(test.mask, [1, 1, 1])
+
+
def test_diag(self):
"Test diag"
x = arange(9).reshape((3, 3))