summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--numpy/ma/extras.py7
-rw-r--r--numpy/ma/tests/test_regression.py8
2 files changed, 11 insertions, 4 deletions
diff --git a/numpy/ma/extras.py b/numpy/ma/extras.py
index 2f3159c49..5a484ce9d 100644
--- a/numpy/ma/extras.py
+++ b/numpy/ma/extras.py
@@ -1402,14 +1402,13 @@ def corrcoef(x, y=None, rowvar=True, bias=False, allow_masked=True, ddof=None):
if rowvar:
for i in range(n - 1):
for j in range(i + 1, n):
- _x = mask_cols(vstack((x[i], x[j]))).var(axis=1,
- ddof=1 - bias)
+ _x = mask_cols(vstack((x[i], x[j]))).var(axis=1, ddof=ddof)
_denom[i, j] = _denom[j, i] = ma.sqrt(ma.multiply.reduce(_x))
else:
for i in range(n - 1):
for j in range(i + 1, n):
- _x = mask_cols(vstack((x[:, i], x[:, j]))).var(axis=1,
- ddof=1 - bias)
+ _x = mask_cols(
+ vstack((x[:, i], x[:, j]))).var(axis=1, ddof=ddof)
_denom[i, j] = _denom[j, i] = ma.sqrt(ma.multiply.reduce(_x))
return c / _denom
diff --git a/numpy/ma/tests/test_regression.py b/numpy/ma/tests/test_regression.py
index f713a8a1a..eb301aa05 100644
--- a/numpy/ma/tests/test_regression.py
+++ b/numpy/ma/tests/test_regression.py
@@ -61,6 +61,14 @@ class TestRegression(TestCase):
a.var(out=mout)
assert_(mout._data == 0)
+ def test_ddof_corrcoef(self):
+ # See gh-3336
+ x = np.ma.masked_equal([1,2,3,4,5], 4)
+ y = np.array([2,2.5,3.1,3,5])
+ r0 = np.ma.corrcoef(x, y, ddof=0)
+ r1 = np.ma.corrcoef(x, y, ddof=1)
+ # ddof should not have an effect (it gets cancelled out)
+ assert_allclose(r0.data, r1.data)
if __name__ == "__main__":
run_module_suite()