prtools.shift#

shift(a, shift, mode='wrap', fill=0.0)[source]#

Shift an array via FFT.

Shift an array by (row, column). The shifts may be non-integer as the shift operation is implemented by introducing a Fourier-domain tilt. If a is complex, the result will also be complex.

Parameters:
  • a (array_like) – The input array.

  • shift ((2,) sequence) – The shift specified as (row, column).

  • mode ({'wrap', 'reflect', 'mirror', 'constant'}, optional) –

    Determines how the input array is extended beyond its boundaries. Default is ‘wrap’.

    • ’wrap’ (a b c d | a b c d | a b c d)

      The input is extended by wrapping around to the opposite edge.

    • ’reflect’ (d c b a | a b c d | d c b a)

      The input is extended by reflecting about the edge of the last pixel. This mode is also sometimes referred to as half-sample symmetric.

    • ’mirror’ (d c b | a b c d | c b a)

      The input is extended by reflecting about the center of the last pixel. This mode is also sometimes referred to as whole-sample symmetric.

    • ’constant’

      The input is extended by filling all values beyond the edge with the same constant value, defined by the fill parameter.

  • fill (scalar, optional) – Value to fill past edges if mode is ‘constant’. Default is 0.0

Returns:

shifted – The shifted input array.

Return type:

ndarray

Example

>>> arr = np.zeros((3,3))
>>> arr[2,2] = 1
>>> arr
array([[0., 0., 0.],
       [0., 0., 0.],
       [0., 0., 1.]])
>>> arr_shift = prtools.shift(arr, shift=(-1,-1))
>>> arr_shift
array([[ 0.00000000e+00, -7.40148683e-17, -2.46716228e-17],
       [-1.16747372e-16,  1.00000000e+00,  2.14548192e-16],
       [-3.12823642e-17,  2.22044605e-16, -4.18468327e-17]])