Next: , Previous: , Up: Arrays   [Contents][Index] Specifying Arrays

One-dimensional numerical arrays can be specified explicitly by listing the elements, separated by commas, and enclosed between square brackets, as shown in the following example:

x = [ 5, 7, 13.0, 23 ]

The data type (see Numerical Data Types) of such a numerical array is the smallest data type that can store all of the elements while (if both integer and floating-point values are present) losing as little precision as possible.

For determining the data type of the array, the data types of the elements are divided into size classes as follows:

  1. byte
  2. word
  3. long, float, cfloat
  4. int64, double, cdouble

The data type of the array is in the greatest size class present among its elements. Moreover, if any of the elements are complex (cfloat, cdouble), then so is the array. Otherwise, if any of the elements are non-complex floating-point (float, double), then so is the array. Otherwise, the array is integer.

One-dimensional string arrays can be specified in the same way as numerical arrays are, by combining the string components. For instance,

s = ['Jill', 'John', 'Joan', 'Jerry Lee Lewis']

generates a string array with four elements.

Arrays with a specific dimensional structure and data type and with all of their elements set to zero can be created through the functions bytarr, intarr, lonarr, int64arr, fltarr, dblarr, cfltarr, cdblarr, strarr, and array (array). For instance,

x = FLTARR(200,100)

creates a float array with dimensions 200 by 100, with undefined elements; i.e., the elements get whatever values happen to be in the memory slots that the elements are assigned to. You can fill the array with specific values through, for instance, the zero, one, and indgen functions (zero, one, indgen).

It is quite easy to request an array that is so large that not enough room for it is available in your computer, or even so large that the number of its bytes does not fit in any integer number type that is available on your computer. For example, you can request an array with 6 dimensions that are each equal to one million (e.g., through N = 1000000 X = BYTARR(N,N,N,N,N,N)); such an array is very much bigger than would fit in all the computer memory that exists today in the whole world. LUX generates an error message if you request an array that is too big.

Next: , Previous: , Up: Arrays   [Contents][Index]