prtools.shift#

shift(x, shift, extend='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:
  • x (array_like) – The input array.

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

  • extend ({'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:

x – 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., 0., 0.],
       [ 0., 1., 0.],
       [ 0., 0., 0.]])