Routines (alphabetical) > Routines: R > REVERSE

# REVERSE

The REVERSE function reverses the order of one dimension of an array.

This routine is written in the IDL language. Its source code can be found in the file `reverse.pro` in the `lib` subdirectory of the IDL distribution.

## Examples

Reverse the order of an array where each element is set to the value of its subscript:

; Create an array:
A = [[0,1,2],[3,4,5],[6,7,8]]
; Print the array:
PRINT, 'Original Array:'
PRINT, A
; Reverse the columns of A.
PRINT, 'Reversed Columns:'
PRINT, REVERSE(A)
; Reverse the rows of A:
PRINT, 'Reversed Rows:'
PRINT, REVERSE(A, 2)

IDL prints:

Original Array:

0 1 2

3 4 5

6 7 8

Reversed Columns:

2 1 0

5 4 3

8 7 6

Reversed Rows:

6 7 8

3 4 5

0 1 2

## Syntax

Result = REVERSE( Array [, Subscript_Index] [, /OVERWRITE] )

## Return Value

Returns the reversed dimension of the array.

## Arguments

### Array

The array containing the original data.

### Subscript_Index

An integer specifying the dimension index (1, 2, 3, etc.) that will be reversed. This argument must be less than or equal to the number of dimensions of Array. If this argument is omitted, the first subscript is reversed.

## Keywords

### OVERWRITE

Set this keyword to conserve memory by doing the transformation “in-place.” The result overwrites the previous contents of the array. This keyword is ignored for one- or two-dimensional arrays.

## Version History

Original | Introduced

## See Also

INVERT, REFORM, ROT, ROTATE, SHIFT, TRANSPOSE