The SHIFT function shifts elements of vectors or arrays along any dimension by any number of elements. 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 = Arrayi for (0 ≤ 1 < n)
where s is the amount of the shift, and n is the number of elements in the array.
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)
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.
Result = SHIFT(Array, S1, ..., Sn)
The result is a vector or array of the same structure and type as Array.
The array to be shifted.
The shift parameters. The Si arguments can be either a single array containing the shift parameters for each dimension, or a sequence of up to eight scalar shift values. For arrays of more than one dimension, the parameter Sn specifies the shift applied to the n-th dimension. S1 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.