What is vector and array processing?
An important part of IDL is the ability to work with data that is organized as vectors and arrays. We will first describe vectors and arrays and then show some tools for constructing them. Finally, we will demonstrate some of their uses. In addition to arrays of numbers, which we will describe here, there are also arrays of strings, structures and objects. You can look up information about them in IDL help if you are eager to find out about them now.Arrays are especially important in signal image processing. We will find that images are just arrays of values with one value for each pixel. Vectors are important in the representation of one-dimensional functions such as functions of time or one spatial dimension.VectorsA vector is a list of data items, and can be constructed with an assignment statement likeA=[1.2, 3.1, 4.6, 5.7]Note that square brackets are used to contain the list. Try typing a list like that shown above and then using HELP,A to get information about the vector.Vectors can contain any of the number types that are accepted by IDL. When the assignment is made all of the numbers are converted to one type. The type that is used is determined by the data type hierarchy. Try typingA=[1, 3B, 4L, 5.7] & HELP,AIDL responds that A is an array of type FLOAT of length 4. If you were to typeA=[1, 3B, 4L, 5] & HELP,Ayou would find that A is now of type LONG. The rule is to convert all of the numbers to the highest number type.ArraysWe can think of a vector as a list that has one dimension. It is a row of data. An array is a list that is arranged in multiple dimensions. A two-dimensional array is a vector of vectors that are all of the same length.C=[[1,2,3,4],[5,6,7,8],[7,6,5,4]] & PRINT,C1 2 3 45 6 7 87 6 5 4We see that A has three rows and four columns and that each row is one of the vectors in the list. An array can contain any of the IDL data types. When it is created all of the numbers are converted to the highest number type. We will describe a number of IDL functions for the construction of arrays. By using these functions one can construct arrays of up to eight dimensions.IndexingColumn and Row IndexIt is important to be able to refer to particular elements of an array. An element in column 1 and row 2 can be referred to by C[1,2]. In the above array we would find that C[1,2]=6. In IDL the column index comes before the row index.Rows and columns are indexed beginning with the number 0. The column indexes of C are 0, 1, 2, 3 and the row indexes are 0, 1, 2. Zero-referenced indexing is a convention that may seem strange at first, but it has programming advantages.One can refer to an entire row by using an asterisk in the column position. C[*,r] refers to the vector in row r. Try the command PRINT,C[*,2].One can refer to an entire column by using an asterisk in the row position. C[col,*] refers to the vector in column col. Try the command PRINT,C[3,*].A part of a row or column can be indexed by providing a list of the elements that are wanted. Try the followingrow =[0,1,2] & col = [3,2,1] & PRINT,C[col,row]Can you explain what is printed?A contiguous segment of column or row elements can be referred to with the notation a:b. For example, C[0:2,2] refers to the elements in positions 0,1,2 in row 2. Try the command PRINT,C[0:2,2]Array IndexEvery element in an array has an array index. The array index is found by counting each element from the beginning of the array to the end row by row. An array that has four columns and three rows would have the indexes as shown below.0 1 2 34 5 6 78 9 10 11Any element in the array can be referred to by its array index. A list of elements in positions 0, 6 and 8 can be printed byk=[0,6,8] & C[k]One can find the value of array index from the row and column indexes. The number of columns, n, has to be known. Then k is simplyk = col + row*nIf k is given then the column and row indexes can be found by integer operations:row = k/ncol = k - row*nFor an array with n=4 columns, C[6]=C[2,1]. You should try converting in both directions.Array Creation ToolsIDL provides a number of functions that can be used to create arrays and initialize their values. The list can be found in the section "Array Creation Routines" in IDL Online Help. A subset of these routines are listed below.BINDGEN Return a byte array with each element set to its subscript.BYTARRCreate a byte vector or array.FINDGEN Return a floating-point array with each element set to its subscript.FLTARRReturn a floating-point vector or array.INDGEN Return an integer array with each element set to its subscript.INTARRReturn an integer vector or array.LINDGEN Return a longword integer array with each element set to its subscript.LONARRReturn a longword integer vector or array.IDENTITY Return an identity array.MAKE_ARRAYGeneral purpose array creation.REPLICATEForm array of given dimensions filled with a value.The functions BYTARR, FLTARR, INTARR, LONARR create arrays with of the type indicated by the first letter of the name and with their initial values set to zero. You can then enter data into them by assignment statements. For example, create an integer array of size 3x4 and set the elements of the first row to the value 3.A=INDGEN(3,4)A[*,0]=3PRINT,AThe functions BINDGEN, INDGEN, FINDGEN, LINDGEN create arrays of the type indicated by the first letter of the name and with the initial values set to the array index. For example, create an array of type byte of size 3x4 and set its initial value to the index.B=BINDGEN(3,4)PRINT,B0 1 23 4 56 7 89 10 11The functions that generate index arrays are very useful in creating a vector of independent variables to be used in calculating and plotting a function. Suppose that you needed to plot the function (1+t2)Cos(5t) over the interval [0,3] in steps of size 0.01. You will then need a vector of 301 values t=[0, .01, .02, ..., 2.99, 3]. You certainly would not want to type all this in. The statements that will do the calculation and plot a graph are given below.t=FINDGEN(301)/100 ;Generates the desired vectorf=(1+t^2)*cos(5*t) ;Calculates the functionplot,t,f ;Draws the graphThe IDENTITY function returns a square array of type float with the elements on the main diagonal set to 1 and all others set to zero. This function is very useful in many linear algebra computations.I=IDENTITY(4)PRINT,IThe REPLICATE function makes an array of the specified size in which a give value placed in all of the positions. To make a 5x2 array in which all of the elements contain the value 3.1 one can useC=REPLICATE(3.1,5,2)PRINT,CThe function MAKE_ARRAY is the most general array creation tool. It has many options which are best described by the online help documentation and the reference manual.