From be90de8e31b76db8154e8ab9cefc21c1d25d0f45 Mon Sep 17 00:00:00 2001 From: Denis Laxalde Date: Tue, 8 May 2012 15:23:42 -0400 Subject: FIX: handle empty arrays in roll --- numpy/core/numeric.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'numpy/core/numeric.py') diff --git a/numpy/core/numeric.py b/numpy/core/numeric.py index 8212dd6ce..d26d9ded8 100644 --- a/numpy/core/numeric.py +++ b/numpy/core/numeric.py @@ -1184,13 +1184,16 @@ def roll(a, shift, axis=None): except IndexError: raise ValueError('axis must be >= 0 and < %d' % a.ndim) reshape = False - shift %= n - indexes = concatenate((arange(n-shift,n),arange(n-shift))) - res = a.take(indexes, axis) - if reshape: - return res.reshape(a.shape) + if n == 0: + return a else: - return res + shift %= n + indexes = concatenate((arange(n-shift,n),arange(n-shift))) + res = a.take(indexes, axis) + if reshape: + return res.reshape(a.shape) + else: + return res def rollaxis(a, axis, start=0): """ -- cgit v1.2.1