summaryrefslogtreecommitdiff
path: root/numpy/lib
diff options
context:
space:
mode:
Diffstat (limited to 'numpy/lib')
-rw-r--r--numpy/lib/function_base.py12
-rw-r--r--numpy/lib/tests/test_function_base.py51
2 files changed, 36 insertions, 27 deletions
diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py
index 3f49af5f1..b2ec9bb5a 100644
--- a/numpy/lib/function_base.py
+++ b/numpy/lib/function_base.py
@@ -1846,8 +1846,8 @@ def cov(m, y=None, rowvar=1, bias=0, ddof=None):
ddof : int, optional
.. versionadded:: 1.5
If not ``None`` normalization is by ``(N - ddof)``, where ``N`` is
- the number of observations. When defined, ``ddof`` overrides the
- value implied by ``bias``. The default value is ``None``.
+ the number of observations; this overrides the value implied by
+ ``bias``. The default value is ``None``.
Returns
-------
@@ -1893,6 +1893,10 @@ def cov(m, y=None, rowvar=1, bias=0, ddof=None):
11.71
"""
+ # Check inputs
+ if ddof is not None and ddof != int(ddof):
+ raise ValueError("ddof must be integer")
+
X = array(m, ndmin=2, dtype=float)
if X.shape[0] == 1:
rowvar = 1
@@ -1961,8 +1965,8 @@ def corrcoef(x, y=None, rowvar=1, bias=0, ddof=None):
ddof : {None, int}, optional
.. versionadded:: 1.5
If not ``None`` normalization is by ``(N - ddof)``, where ``N`` is
- the number of observations. When defined, ``ddof`` overrides the
- value implied by ``bias``. The default value is ``None``.
+ the number of observations; this overrides the value implied by
+ ``bias``. The default value is ``None``.
Returns
-------
diff --git a/numpy/lib/tests/test_function_base.py b/numpy/lib/tests/test_function_base.py
index 5d0f8aa45..037e8043a 100644
--- a/numpy/lib/tests/test_function_base.py
+++ b/numpy/lib/tests/test_function_base.py
@@ -821,30 +821,35 @@ class TestNanFunctsIntTypes(TestCase):
class TestCorrCoef(TestCase):
+ A = array([[ 0.15391142, 0.18045767, 0.14197213],
+ [ 0.70461506, 0.96474128, 0.27906989],
+ [ 0.9297531 , 0.32296769, 0.19267156]])
+ B = array([[ 0.10377691, 0.5417086 , 0.49807457],
+ [ 0.82872117, 0.77801674, 0.39226705],
+ [ 0.9314666 , 0.66800209, 0.03538394]])
+ res1 = array([[ 1. , 0.9379533 , -0.04931983],
+ [ 0.9379533 , 1. , 0.30007991],
+ [-0.04931983, 0.30007991, 1. ]])
+ res2 = array([[ 1. , 0.9379533 , -0.04931983,
+ 0.30151751, 0.66318558, 0.51532523],
+ [ 0.9379533 , 1. , 0.30007991,
+ - 0.04781421, 0.88157256, 0.78052386],
+ [-0.04931983, 0.30007991, 1. ,
+ - 0.96717111, 0.71483595, 0.83053601],
+ [ 0.30151751, -0.04781421, -0.96717111,
+ 1. , -0.51366032, -0.66173113],
+ [ 0.66318558, 0.88157256, 0.71483595,
+ - 0.51366032, 1. , 0.98317823],
+ [ 0.51532523, 0.78052386, 0.83053601,
+ - 0.66173113, 0.98317823, 1. ]])
+
def test_simple(self):
- A = array([[ 0.15391142, 0.18045767, 0.14197213],
- [ 0.70461506, 0.96474128, 0.27906989],
- [ 0.9297531 , 0.32296769, 0.19267156]])
- B = array([[ 0.10377691, 0.5417086 , 0.49807457],
- [ 0.82872117, 0.77801674, 0.39226705],
- [ 0.9314666 , 0.66800209, 0.03538394]])
- assert_almost_equal(corrcoef(A),
- array([[ 1. , 0.9379533 , -0.04931983],
- [ 0.9379533 , 1. , 0.30007991],
- [-0.04931983, 0.30007991, 1. ]]))
- assert_almost_equal(corrcoef(A, B),
- array([[ 1. , 0.9379533 , -0.04931983,
- 0.30151751, 0.66318558, 0.51532523],
- [ 0.9379533 , 1. , 0.30007991,
- - 0.04781421, 0.88157256, 0.78052386],
- [-0.04931983, 0.30007991, 1. ,
- - 0.96717111, 0.71483595, 0.83053601],
- [ 0.30151751, -0.04781421, -0.96717111,
- 1. , -0.51366032, -0.66173113],
- [ 0.66318558, 0.88157256, 0.71483595,
- - 0.51366032, 1. , 0.98317823],
- [ 0.51532523, 0.78052386, 0.83053601,
- - 0.66173113, 0.98317823, 1. ]]))
+ assert_almost_equal(corrcoef(self.A), self.res1)
+ assert_almost_equal(corrcoef(self.A, self.B), self.res2)
+
+ def test_ddof(self):
+ assert_almost_equal(corrcoef(self.A, ddof=-1), self.res1)
+ assert_almost_equal(corrcoef(self.A, self.B, ddof=-1), self.res2)
class Test_i0(TestCase):