# [SciPy-User] Is this a bug in scipy.ndimage.interpolation.shift ???

Jerome Kieffer Jerome.Kieffer@esrf...
Tue Aug 23 09:25:13 CDT 2011

```Hello,

I was using scipy.ndimage.interpolation.shift with order=0 and "wrap" mode because I did not want to swap the 4 blocs of memory myself ... but I got strange results.

for shifting by hand  one can do:
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
@return: shifted image
"""
re = numpy.zeros_like(input)
s0, s1 = input.shape
d0 = shift[0] % s0
d1 = shift[0] % 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

In [327]: a=np.random.random((5,5))

In [328]: scipy.ndimage.interpolation.shift(a,(2,3),order=0,mode="wrap")-shift(a,(2,3))
Out[328]:
array([[-0.13484701,  0.43450823,  0.4920127 , -0.04826882, -0.40258904],
[ 0.48403199,  0.02161651, -0.35774838,  0.73954376,  0.42218297],
[-0.23808862,  0.4799521 , -0.39548832,  0.        ,  0.        ],
[-0.04105354,  0.06934301, -0.18976602,  0.        ,  0.        ],
[-0.38430434,  0.04591371, -0.33502248,  0.        ,  0.        ]])

SHOULD BE 0 everywhere and it is only in the lower right corner ...

Do you agree this is an error (or did I misinterpret scipy.ndimage.interpolation.shift since the begining ?)

Shall I open a bug ? I am using an ubuntu 10.04 (LTS)

Cheers,
--
Jérôme Kieffer
On-Line Data analysis / Software Group
ISDD / ESRF
tel +33 476 882 445
```