Skip to main content

2.5) Array Operations (cont'd)


IDL arrays are column major, which means that the first dimension of an array refers to the columns, the second to the rows and so on. So if we create a 2D array of size (mxn):

a = intarr(m,n)

it will be laid out as shown below.

Note that IDL starts counting from 0 not 1. So the first element of an array is always 0 and the last element is (number of elements - 1).

We can refer to elements within an array using brackets and their array subscripts. Type the following at the IDL command prompt.

X = [0,1,2,3,4,5]

X is now an array containing the numbers 0-5. We can print the value of a particular element using:

print, X(0)
print, X(4)

This will print the first element (0) and the fifth element (4) of X to the screen.

We can also refer to a subset or range of elements of the array using a colon ":".

print, X(2:5)

This will print the values of the elements 2, 3, 4 and 5 of X to the screen.