From 1dcf0c96df5e2f7b861c6054ead2ad7ebc77aa79 Mon Sep 17 00:00:00 2001 From: Ralf Gommers Date: Tue, 29 Mar 2011 20:02:13 +0200 Subject: BUG: handle empty inputs in cov and corrcoef. Closes #1773. --- numpy/lib/function_base.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'numpy/lib/function_base.py') 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 -- cgit v1.2.1