# [Scipy-tickets] [SciPy] #1520: ndimage.shift produces incorrect output

SciPy Trac scipy-tickets@scipy....
Thu Sep 15 17:58:28 CDT 2011

```#1520: ndimage.shift produces incorrect output
---------------------------+------------------------------------------------
Reporter:  stefan         |       Owner:  somebody
Type:  defect         |      Status:  new
Priority:  normal         |   Milestone:  Unscheduled
Component:  scipy.ndimage  |     Version:  devel
Keywords:                 |
---------------------------+------------------------------------------------
{{{
def shift(input, shift):
"""
Shift an array like  scipy.ndimage.interpolation.shift(input, shift,
mode="wrap", order=0) but faster
@param in: 2d numpy array
@param d: 2-tuple of integers=20
@return: shifted image
"""
re =  numpy.zeros_like(input)
s0, s1 =  input.shape
d0 =  shift[0] % s0
d1 =  shift[1] % s1
r0 =  (-d0) % s0
r1 =  (-d1) % s1
re[d0:, d1:] =  input[:r0, :r1]
re[:d0, d1:] =  input[r0:, :r1]
re[d0:, :d1] =  input[:r0, r1:]
re[:d0, :d1] =  input[r0:, r1:]
return re

a=np.arange(12).reshape((3,4))
print "Input:\n", a, "\n"
print "Ndimage:\n", interpolation.shift(a, (1, 1), mode="wrap", order=0),
"\n"
print "Custom:\n", shift(a, (1, 1)), "\n"
}}}

Output:

{{{
Input:
[[ 0  1  2  3]
[ 4  5  6  7]
[ 8  9 10 11]]

Ndimage:
[[6 4 5 6]
[2 0 1 2]
[6 4 5 6]]

Custom:
[[11  8  9 10]
[ 3  0  1  2]
[ 7  4  5  6]]
}}}

--
Ticket URL: <http://projects.scipy.org/scipy/ticket/1520>
SciPy <http://www.scipy.org>
SciPy is open-source software for mathematics, science, and engineering.
```