summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2013-05-17 05:43:26 -0700
committerCharles Harris <charlesr.harris@gmail.com>2013-05-17 05:43:26 -0700
commit029060d84e1a329d0221d861f47ded9edee28633 (patch)
treea53844b1e8cdf8db8b684e7b70d64f4f7d00e732
parentae30efd25e6797c4d97775c6ca40b47bc54a3df3 (diff)
parent4c291f361fdc8c756e6b1cd7ff7ce2c2ddfc5ed9 (diff)
downloadnumpy-029060d84e1a329d0221d861f47ded9edee28633.tar.gz
Merge pull request #3337 from seberg/issue-3336
BUG: Correctly pass on ddof paramter on inside np.ma.corrcoef
-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()