Skip to main content

2.4) Arrays


IDL allows you to work with multi-dimensional data sets through the use of arrays. In it's simplest form, a 1D array is analogous to a vector, a 2D array is like a matrix. An array can have any number of dimensions and can be of any data type (integer, float, string, etc.), but all data in the array must be of the same type.

There are several ways to create arrays, the 2 most common methods are:

  1. Direct data input using square brackets (most useful for 1D arrays)
  2. ; This will create a 5 element integer array containing the numbers 1-5
    data_array = [1,2,3,4,5]
    
  3. Define an array to put data into later
  4. ; A 2D integer array (5x5) filled with zeros
    data_array = intarr(5,5)
    ; A 3D floating point array (5x5x5) filled with zeros
    data_array = fltarr(5,5,5)
    ; A 4D string array (5x5x5x5) filled with blank strings
    data_array = strarr(5,5,5,5)
    ; A 5D double precision array (5x5x5x5x5) filled with zeros
    data_array = dblarr(5,5,5,5,5)
    

You can also create an array filled with values in which each element has a value equal to it's array subscript.