Skip to main content

2.6) Array Operations (cont'd)


You can also refer to the elements in a multi-dimensional array in the same way, using the subscripts for the columns, rows, etc., separated by a comma. So if we create a 2 dimensional (5x5) array using:

X = fltarr(5,5)

We can the refer to a particular element of the array using it's column and row index. So for example if we want to print the value of the element located in the first column of the fourth row, we use:

print, X(0,3)

As with 1 dimensional subscripts, we can also use ranges for a particular dimension. So if we want to print the values of the first three columns of the second row, we use:

print, X(0:2,1)

We can use an asterisk "*" to refer to all elements in a particular dimension. so if we want to print the entire first column of our array (i.e. all rows), we use:

print, X(0,*)

Note, we didn't fill the array with any data, so IDL will print "0" for each if the above statements.