summaryrefslogtreecommitdiff
path: root/numpy
diff options
context:
space:
mode:
Diffstat (limited to 'numpy')
-rw-r--r--numpy/lib/function_base.py66
-rw-r--r--numpy/lib/tests/test_function_base.py4
-rw-r--r--numpy/lib/tests/test_regression.py4
-rw-r--r--numpy/oldnumeric/mlab.py2
4 files changed, 30 insertions, 46 deletions
diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py
index 7c61180f3..10ea7707d 100644
--- a/numpy/lib/function_base.py
+++ b/numpy/lib/function_base.py
@@ -1839,15 +1839,15 @@ def cov(m, y=None, rowvar=1, bias=0, ddof=None):
is transposed: each column represents a variable, while the rows
contain observations.
bias : int, optional
- Default normalization is by ``(N-1)``, where ``N`` is the number of
+ Default normalization is by ``(N - 1)``, where ``N`` is the number of
observations given (unbiased estimate). If `bias` is 1, then
- normalization is by ``N``. Deprecated in numpy 1.5, use ddof
- instead.
+ normalization is by ``N``. These values can be overridden by using
+ the keyword ``ddof`` in numpy versions >= 1.5.
ddof : int, optional
- Normalization is by ``(N - ddof)``, where ``N`` is the number of
- observations. Setting ddof=1 gives the usual unbiased estimate.
- Default will be ``None`` until the `bias` keyword is removed and
- will be 0 thereafter.
+ .. 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``.
Returns
-------
@@ -1871,7 +1871,7 @@ def cov(m, y=None, rowvar=1, bias=0, ddof=None):
Note how :math:`x_0` increases while :math:`x_1` decreases. The covariance
matrix shows this clearly:
- >>> np.cov(x, ddof=1)
+ >>> np.cov(x)
array([[ 1., -1.],
[-1., 1.]])
@@ -1883,17 +1883,16 @@ def cov(m, y=None, rowvar=1, bias=0, ddof=None):
>>> x = [-2.1, -1, 4.3]
>>> y = [3, 1.1, 0.12]
>>> X = np.vstack((x,y))
- >>> print np.cov(X, ddof=1)
+ >>> print np.cov(X)
[[ 11.71 -4.286 ]
[ -4.286 2.14413333]]
- >>> print np.cov(x, y, ddof=1)
+ >>> print np.cov(x, y)
[[ 11.71 -4.286 ]
[ -4.286 2.14413333]]
- >>> print np.cov(x, ddof=1)
+ >>> print np.cov(x)
11.71
"""
-
X = array(m, ndmin=2, dtype=float)
if X.shape[0] == 1:
rowvar = 1
@@ -1916,16 +1915,11 @@ def cov(m, y=None, rowvar=1, bias=0, ddof=None):
N = X.shape[0]
if ddof is None:
- if bias:
- msg = "The bias keyword is deprecated, "\
- "use ddof=0 instead of bias=1"
- ddof = 0
- else:
- msg = "The bias keyword is deprecated, "\
- "use ddof=1 instead of bias=0"
+ if bias == 0:
ddof = 1
- warnings.warn(msg, DeprecationWarning)
- fact = N - ddof
+ else:
+ ddof = 0
+ fact = float(N - ddof)
if not rowvar:
return (dot(X.T, X.conj()) / fact).squeeze()
@@ -1960,15 +1954,15 @@ def corrcoef(x, y=None, rowvar=1, bias=0, ddof=None):
is transposed: each column represents a variable, while the rows
contain observations.
bias : int, optional
- Default normalization is by ``(N-1)``, where ``N`` is the number of
- observations given (unbiased estimate). If `bias` is 1, then
- normalization is by ``N``. Deprecated in numpy 1.5, use ddof
- instead.
- ddof : int, optional
- Normalization is by ``(N - ddof)``, where ``N`` is the number of
- observations. Setting ddof=1 gives the usual unbiased estimate.
- Default will be ``None`` until the `bias` keyword is removed and
- will be 0 thereafter.
+ Default normalization is by ``(N - 1)``, where ``N`` is the number of
+ observations (unbiased estimate). If `bias` is 1, then
+ normalization is by ``N``. These values can be overridden by using
+ the keyword ``ddof`` in numpy versions >= 1.5.
+ 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``.
Returns
-------
@@ -1980,17 +1974,7 @@ def corrcoef(x, y=None, rowvar=1, bias=0, ddof=None):
cov : Covariance matrix
"""
- if ddof is None:
- if bias:
- msg = "The bias keyword is deprecated, "\
- "use ddof=0 instead of bias=1"
- ddof = 0
- else:
- msg = "The bias keyword is deprecated, "\
- "use ddof=1 instead of bias=0"
- ddof = 1
- warnings.warn(msg, DeprecationWarning)
- c = cov(x, y, ddof=ddof)
+ c = cov(x, y, bias=bias, ddof=ddof)
try:
d = diag(c)
except ValueError: # scalar covariance
diff --git a/numpy/lib/tests/test_function_base.py b/numpy/lib/tests/test_function_base.py
index 6be1b204f..5d0f8aa45 100644
--- a/numpy/lib/tests/test_function_base.py
+++ b/numpy/lib/tests/test_function_base.py
@@ -828,11 +828,11 @@ class TestCorrCoef(TestCase):
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, ddof=1),
+ 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, ddof=1),
+ assert_almost_equal(corrcoef(A, B),
array([[ 1. , 0.9379533 , -0.04931983,
0.30151751, 0.66318558, 0.51532523],
[ 0.9379533 , 1. , 0.30007991,
diff --git a/numpy/lib/tests/test_regression.py b/numpy/lib/tests/test_regression.py
index c5483556c..a8804ac3a 100644
--- a/numpy/lib/tests/test_regression.py
+++ b/numpy/lib/tests/test_regression.py
@@ -14,8 +14,8 @@ class TestRegression(TestCase):
"""Ticket #91"""
x = np.random.random((3,3))
y = x.copy()
- np.cov(x, rowvar=1, ddof=1)
- np.cov(y, rowvar=0, ddof=1)
+ np.cov(x, rowvar=1)
+ np.cov(y, rowvar=0)
assert_array_equal(x,y)
def test_mem_digitize(self,level=rlevel):
diff --git a/numpy/oldnumeric/mlab.py b/numpy/oldnumeric/mlab.py
index 4f750cb85..e2a0262f0 100644
--- a/numpy/oldnumeric/mlab.py
+++ b/numpy/oldnumeric/mlab.py
@@ -92,7 +92,7 @@ def cov(m, y=None, rowvar=0, bias=0):
from numpy import sqrt, multiply
def corrcoef(x, y=None):
- c = cov(x, y, ddof=1)
+ c = cov(x, y)
d = diag(c)
return c/sqrt(multiply.outer(d,d))