diff options
Diffstat (limited to 'numpy')
-rw-r--r-- | numpy/core/numeric.py | 21 | ||||
-rw-r--r-- | numpy/lib/shape_base.py | 2 |
2 files changed, 21 insertions, 2 deletions
diff --git a/numpy/core/numeric.py b/numpy/core/numeric.py index 541a54739..2bb8013b9 100644 --- a/numpy/core/numeric.py +++ b/numpy/core/numeric.py @@ -7,7 +7,7 @@ __all__ = ['newaxis', 'ndarray', 'flatiter', 'ufunc', 'asarray', 'asanyarray', 'ascontiguousarray', 'asfortranarray', 'isfortran', 'empty_like', 'zeros_like', 'correlate', 'convolve', 'inner', 'dot', 'outer', 'vdot', - 'alterdot', 'restoredot', 'rollaxis', 'cross', 'tensordot', + 'alterdot', 'restoredot', 'roll', 'rollaxis', 'cross', 'tensordot', 'array2string', 'get_printoptions', 'set_printoptions', 'array_repr', 'array_str', 'set_string_function', 'little_endian', 'require', @@ -332,6 +332,25 @@ def tensordot(a, b, axes=2): res = dot(at, bt) return res.reshape(olda + oldb) +def roll(a, shift, axis=None): + """Roll the elements in the array by 'shift' positions along + the given axis. + """ + a = asanyarray(a) + if axis is None: + n = a.size + reshape=1 + else: + n = a.shape[axis] + reshape=0 + 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): """Return transposed array so that axis is rolled before start. diff --git a/numpy/lib/shape_base.py b/numpy/lib/shape_base.py index c6dc7b5c9..e20da62ae 100644 --- a/numpy/lib/shape_base.py +++ b/numpy/lib/shape_base.py @@ -1,6 +1,6 @@ __all__ = ['atleast_1d','atleast_2d','atleast_3d','vstack','hstack', 'column_stack','row_stack', 'dstack','array_split','split','hsplit', - 'vsplit','dsplit','apply_over_axes','expand_dims', + 'vsplit','dsplit','apply_over_axes','expand_dims', 'apply_along_axis', 'kron', 'tile', 'get_array_wrap'] import numpy.core.numeric as _nx |