summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulian Taylor <jtaylor.debian@googlemail.com>2014-02-27 20:39:12 +0100
committerJulian Taylor <jtaylor.debian@googlemail.com>2014-02-27 20:39:58 +0100
commitdf84ecfea50ef33a1259c67c534a09238c0eefc8 (patch)
tree3c80f3fdde690886736a0b86d12d309873bc2cc1
parent8c4d9bedd9d85d86c41f956cdb5140e112c2ac08 (diff)
downloadnumpy-df84ecfea50ef33a1259c67c534a09238c0eefc8.tar.gz
BUG: accept non arrays in cor and corrcoeff
closes gh-4295
-rw-r--r--numpy/lib/function_base.py2
-rw-r--r--numpy/lib/tests/test_function_base.py4
2 files changed, 6 insertions, 0 deletions
diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py
index 63b191b07..586c93074 100644
--- a/numpy/lib/function_base.py
+++ b/numpy/lib/function_base.py
@@ -1810,9 +1810,11 @@ def cov(m, y=None, rowvar=1, bias=0, ddof=None):
"ddof must be integer")
# Handles complex arrays too
+ m = np.asarray(m)
if y is None:
dtype = np.result_type(m, np.float64)
else:
+ y = np.asarray(y)
dtype = np.result_type(m, y, np.float64)
X = array(m, ndmin=2, dtype=dtype)
diff --git a/numpy/lib/tests/test_function_base.py b/numpy/lib/tests/test_function_base.py
index 953292550..d6705072e 100644
--- a/numpy/lib/tests/test_function_base.py
+++ b/numpy/lib/tests/test_function_base.py
@@ -1204,6 +1204,10 @@ class TestCorrCoef(TestCase):
[0.66318558, 0.88157256, 0.71483595, -0.51366032, 1., 0.98317823],
[0.51532523, 0.78052386, 0.83053601, -0.66173113, 0.98317823, 1.]])
+ def test_non_array(self):
+ assert_almost_equal(np.corrcoef([0, 1, 0], [1, 0, 1]),
+ [[1., -1.], [-1., 1.]])
+
def test_simple(self):
assert_almost_equal(corrcoef(self.A), self.res1)
assert_almost_equal(corrcoef(self.A, self.B), self.res2)