Logical Data
Logical (Boolean) data consists of only ones and zeros. The relational functions
(> 2 < <+) generate logical data as their result; the result is 1 if the condition was
true ahd 0 if the condition was false. The output can then be used as arguments
to the logical functions (AZd-1 to check for certain conditions being true or false.
SCALAR
A single item, whether a single number or single character constant, is called a scalar.
It has no coordinates; that is, it can be thought of as a geometric point. The follow-
ing are examples of scalars:
Scalars can be used directly in calculations or can be assigned to a variable name.
The variable name for the scalar can then be used in the calculations:
ARRAYS
Array is the general term for a collection of data, and includes scalars (single data
items), vectors (strings of data), matrices (tables of data), and arrays of higher
dimensions (multiple tables). All primitive (built-in) functions are designed to handle
arrays. Some functions are designed specifically to handle arrays rather than scalars.
Indexing, for example, can select certain elements from an array for processing.
One of the simplest kinds of arrays, the vector, has only one dimension; it can be
thought of as a collection of elements arranged along a horizontal line. The num-
bers that indicate the positions of elements in an array are called indices. An element
can be selected from a vector by a single index, since a vector has only one dimen-
sion. The following example shows assigning a numeric and a character vector to two
variable names, N
and C; the names are then entered to display the values they re-
present:
10 i
32
Generating Arrays
c:
The most common way to generate an array is to specify the following: the shape
the array is to have-that is, the length of each coordinate; the values of the ele-
ments of the new array. The APL function that forms an array is the reshape
function. The symbol for the reshape function is p. The format of the function
used to generate an array is XpY, where X is the shape of the array and Y represents
the values for the elements of the array. For the left argument (X), you enter a
number for each coordinate to be generated; this number indicates the length of
the coordinate. Each number in the left argument must be separated by at least one
blank. The values of the elements of the new array are whatever you enter as the
right argument (Y). The instruction 7pA means that the array to be generated has
one dimension (is a vector) seven elements in length, and that seven values are to
be supplied from whatever values are found stored under the name A. It does not
matter how many elements A has, as long as it has at least one element. If A has
fewer than seven elements, its elements are repeated as often as needed to provide
seven entries in the new vector. If A has more than seven elements, the first seven
are used. The following examples show generation of some vectors:
'7 p 1. 2 3
:I. 2 3 d 2 3 :I.
2 p :I. 2 3
I. 2 3 :I. 2 3
,.! (" 1. I 3
1. I ;3 1. , 3 :I. , 3 1. I 3 :I. 1 3
t:.
An array with two coordinates (rows and columns) is called a matrix.
Columns
-
")
123
5 6 7 9 > Rows
9 10 11 12 I
To generate a matrix, you specify X (left argument) as two numbers, which are the
lengths of the two coordinates. The first number in X is the length of the first co-
ordinate, or number of rows, and the second number is the length of the second
coordinate, or number of columns. The following example shows how a matrix is
generated:
33
Previous Page Next Page