Working with Matrices

Subscript Reduction Operators

You can use reduction operators, which return a matrix of reduced dimension, in place of values for subscripts to get reductions across all rows and columns. Table 4.3 lists the eight operators for subscript reduction in IML.

Table 4.3: Subscript Reduction Operators
Operator   Action
+ addition
\char93  multiplication
> maximum
< minimum
\lt:\gt index of maximum
\gt:\lt index of minimum
: mean
\char93 \char93  sum of squares

For example, to get column sums of the matrix x (sum across the rows, which reduces the row dimension to 1), specify X[+,]. The first subscript (+) specifies that summation reduction take place across the rows. Omitting the second subscript, corresponding to columns, leaves the column dimension unchanged. The elements in each column are added, and the new matrix consists of one row containing the column sums.

You can use these operators to reduce either rows or columns or both. When both rows and columns are reduced, row reduction is done first.

For example, the expression A[+,\lt\gt] results in the maximum (\lt\gt) of the column sums (+).

You can repeat reduction operators. To get the sum of the row maxima, use the expression A[,\lt\gt] [+,].

A subscript such as A[\{2 3\},+] first selects the second and third rows of a and then finds the row sums of that matrix. The following examples demonstrate how to use the operators for subscript reduction.

Consider the following matrix a:

{let } a =   [ 0 & 1 & 2 \    5 & 4 & 3 \    7 & 6 & 8 \    ]

The following statements are true:

a[{2 3},+] { yields }   [ 12 \    21 \    ]   { (row sums for rows 2 and 3)}
a[+,\lt\gt] { yields }   [ 13 \    ]   { (maximum of column sums)}
a[\lt\gt,+] { yields }   [ 21 \    ]   { (sum of column maxima)}
a[,\gt\lt] [+,] { yields }   [ 9 \    ]   { (sum of row minima)}
a[,\lt:\gt] { yields }   [ 3 \    1 \    3 \    ]   { (indices of row maxima)}
a[\gt:\lt,] { yields }   [ 1 & 1 & 1 \    ]   { (indices of column minima)}
a[:] { yields }   [ 4 \    ]   { (mean of all elements)}

Previous Page | Next Page | Top of Page