Closed scipy-gitbot closed 9 years ago
Original ticket http://projects.scipy.org/scipy/ticket/1520 on 2011-09-15 by @stefanv, assigned to unknown.
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]]
trac user jjhelmus wrote on 2012-05-08
This ticket identies the same problem as Ticket gh-1323.
Added example to gh-1323, closing this as duplicate.
Original ticket http://projects.scipy.org/scipy/ticket/1520 on 2011-09-15 by @stefanv, assigned to unknown.
Output: