INDEX_CONV Function

Standard Library function that converts 1-dimensional indices to n-dimensional indices, or n-dimensional indices to 1-dimensional indices.

enabled.

Usage

    j = INDEX_CONV( a, i )

Input Parameters

a—An n-dimensional array.

i—A vector of m one-dimensional indices into a, or an m-by-n array of m n-dimensional indices into a.

Returned Value

j—An m-by-n array of m n-dimensional indices into a (if i is one-dimensional) or a vector of m one-dimensional indices into a (if i is two-dimensional).

Keywords

Dims—If Dims is set to any scalar then the first argument, a, which is normally an array, should instead be a vector of dimensions for an array. Sometimes it is useful to do index conversions relative to a virtual array, and since conversions are a function only of array dimensions, the Dims keyword allows them to be computed without actually creating an array. Dims is not set by default.

Discussion

Elements in an ND array can be identified with ND indices in the usual way, and they can also be identified with 1D indices which reflect their position in memory. Conversions between these two types of indices are among the most common operations required in array-based programming, and INDEX_CONV performs these conversions.

Example

This example creates a 2D array of 6 elements and converts all of its 1D indices to 2D indices. The 2D indices are then converted back to the original 1D indices.

a = INDGEN( 2, 3 ) 
j = INDEX_CONV( a, INDGEN(6) ) 
PM, j
; PV-WAVE prints:
;   0           0
;   1           0
;   0           1
;   1           1
;   0           2
;   1           2
PM, INDEX_CONV( a, j )
; PV-WAVE prints:
;   0
;   1
;   2
;   3
;   4
;   5