diff options
author | Ralf Gommers <ralf.gommers@googlemail.com> | 2011-03-29 20:02:13 +0200 |
---|---|---|
committer | Ralf Gommers <ralf.gommers@googlemail.com> | 2011-04-02 12:03:41 +0200 |
commit | 1dcf0c96df5e2f7b861c6054ead2ad7ebc77aa79 (patch) | |
tree | 3867e9a942752a1047c49ffe6111663f87f9ebc5 /numpy/lib/function_base.py | |
parent | 89db53b1f437d846829a3c387ea61001b3b66383 (diff) | |
download | numpy-1dcf0c96df5e2f7b861c6054ead2ad7ebc77aa79.tar.gz |
BUG: handle empty inputs in cov and corrcoef. Closes #1773.
Diffstat (limited to 'numpy/lib/function_base.py')
-rw-r--r-- | numpy/lib/function_base.py | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/numpy/lib/function_base.py b/numpy/lib/function_base.py index 34c136064..02c9b5349 100644 --- a/numpy/lib/function_base.py +++ b/numpy/lib/function_base.py @@ -1970,6 +1970,9 @@ def cov(m, y=None, rowvar=1, bias=0, ddof=None): raise ValueError("ddof must be integer") X = array(m, ndmin=2, dtype=float) + if X.size == 0: + # handle empty arrays + return np.array(m) if X.shape[0] == 1: rowvar = 1 if rowvar: @@ -2017,7 +2020,7 @@ def corrcoef(x, y=None, rowvar=1, bias=0, ddof=None): Parameters ---------- - m : array_like + x : array_like A 1-D or 2-D array containing multiple variables and observations. Each row of `m` represents a variable, and each column a single observation of all those variables. Also see `rowvar` below. @@ -2051,6 +2054,9 @@ def corrcoef(x, y=None, rowvar=1, bias=0, ddof=None): """ c = cov(x, y, rowvar, bias, ddof) + if c.size == 0: + # handle empty arrays + return c try: d = diag(c) except ValueError: # scalar covariance |