Next: asciisave()
Up: MacAnova Help File
Previous: array()
Contents
Usage:
Create an array by a <- array(data,dim1,...,dimk)
Extract elements by b <- a[j1,...,jk]
Determine the number of dimensions ndims(a)
Determine the dimensions dim(a)
Determine the number of elements length(a)
Reorder subscripts by b <- a' or b <- t(a,J), permutation
vector J
|
Keywords:
variables
Description
Any REAL, LOGICAL or CHARACTER variable is an array with some number of
dimensions, say M. To extract or change any single element of an array
you need M subscripts, j_1, j_2, ..., j_M. See topic 'subscripts'.
The "dimensions" of an array are the maximum permitted values for each
of the M subscripts. If the dimensions are N_1, N_2, ..., N_M, we
sometimes say the array is N_1 by N_2 by ... by N_M.
When extracting or changing elements of an array using subscripts, it is
an error if any subscript j_k > N_k.
You can create an array A by
Cmd> A <- array(a,N_1,N_2,...,N_M).
where a is a vector or array with exactly N_1*N_2*...*N_M elements.
A one dimensional array is called a vector and a two dimensional array
is called a matrix. See topic 'vectors' and 'matrices'.
Order of elements
Elements of an array are stored with the first subscript changing most
rapidly, the second changing second most rapidly, and so on, with the
last subscript changing least rapidly. Thus for a 2 by 2 by 2 array,
the elements are in the order
a[1,1,1], a[2,1,1], a[1,2,1], a[2,2,1], a[1,1,2], a[2,1,2],
a[1,2,2],a[2,2,2]
Functions of arrays
There are several functions that are helpful in working with arrays. In
the following, A is an array.
length(A) The number of elements in A
ndims(A) The number of dimensions M of A
dim(A) The sizes vector(N1,...,NM) of all the dimensions of A
a' or t(a) The same elements of a, with dimensions reversed, so
that a'[j1,j2,...,jk] is a[jk,...,j2,j1]
t(a,J) The same elements of a with dimensions permuted by
elements of vector J so that t(a,J)[K[1],K[2],...,K[k]]
is a[K[J[1]],K[J[2]],...,K[J[k]]]
vector(a) The elements of a in a vector retaining the order.
max(a), min(a), sum(a) and prod(a) operate along the first dimension of
a, returning an array with the same number of dimensions with the first
dimension 1.
Transformations of an array a such as cos(a) and sqrt(a) return arrays
with the same dimensions as a.
Cross references
See also 'variables', 'scalars', 'vectors', 'matrices', length(),
ndims(), dim(), t(), vector(), matrix(), array().
Gary Oehlert
2006-01-30