diff options
author | Charles Harris <charlesr.harris@gmail.com> | 2013-04-01 15:25:27 -0700 |
---|---|---|
committer | Charles Harris <charlesr.harris@gmail.com> | 2013-04-01 15:25:27 -0700 |
commit | a6385b3a99e508e0d2ed5a6397da29d05da27ceb (patch) | |
tree | 61f036ade95db2dd8ffcd761674c6f1fcde74a58 /numpy/core/numeric.py | |
parent | 5ad97ea70b126a1a13abc4d7500f0281ba4ddd50 (diff) | |
parent | 8d83ae93706d3486447a9b40908995b406178111 (diff) | |
download | numpy-a6385b3a99e508e0d2ed5a6397da29d05da27ceb.tar.gz |
Merge pull request #273 from dlax/fix/roll
somes fixes for the roll function
Diffstat (limited to 'numpy/core/numeric.py')
-rw-r--r-- | numpy/core/numeric.py | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/numpy/core/numeric.py b/numpy/core/numeric.py index 57e366efb..fd7f06ca6 100644 --- a/numpy/core/numeric.py +++ b/numpy/core/numeric.py @@ -1153,15 +1153,19 @@ def roll(a, shift, axis=None): n = a.size reshape = True else: - n = a.shape[axis] + try: + n = a.shape[axis] + except IndexError: + raise ValueError('axis must be >= 0 and < %d' % a.ndim) reshape = False + if n == 0: + return a shift %= n - indexes = concatenate((arange(n-shift,n),arange(n-shift))) + indexes = concatenate((arange(n - shift, n), arange(n - shift))) res = a.take(indexes, axis) if reshape: - return res.reshape(a.shape) - else: - return res + res = res.reshape(a.shape) + return res def rollaxis(a, axis, start=0): """ |