##
SHIFT

The
SHIFT function shifts elements of vectors or
arrays along any dimension by any number of elements. The result is a vector or array of the same structure and type as *
Array*
. Positive shifts are to the right while left shifts are expressed as a negative number. All shifts are circular.

Elements shifted off one end wrap around and are shifted onto the other end. In the case of vectors the action of SHIFT can be expressed:

Result_{
(i + s) modulation}
= Array_{
i}
for (0 *
£*
1 < *
n*
)

where *
s*
is the amount of the shift, and *
n*
is the number of elements in the array.

###
Calling Sequence

Result = SHIFT(*
Array, S*
_{
1}
*
, ..., S*
_{
n}
)

###
Arguments

####
Array

The array to be shifted.

####
S_{
i}

The shift parameters. For arrays of more than one dimension, the parameter *
S*
_{
n}
specifies the shift applied to the *
n*
th dimension. *
S*
_{
1}
specifies the shift along the first dimension and so on. If only one shift parameter is present and the parameter is an array, the array is treated as a vector (i.e., the array is treated as having one-dimensional subscripts).

A shift specification of 0 means that no shift is to be performed along that dimension.

###
Example

The following example demonstrates using SHIFT with a vector. by entering:

A = INDGEN(5)

Print the original vector, the vector shifted one position to the right, and the vector shifted one position to the left:

PRINT, A, SHIFT(A, 1), SHIFT(A, -1)

Executing these statements gives the result:

0 1 2 3 4

4 0 1 2 3

1 2 3 4 0

Notice how elements of the vector that shift off the end wrap around to the other end. This "wrap around" occurs when shifting arrays of any dimension.