| Working with Matrices |
Elementwise binary operators produce a result matrix from element-by-element operations on two argument matrices.
Table 4.2 lists the elementwise binary operators.
Table 4.2: Elementwise Binary Operators| Operator | Action | |
| addition, concatenation | ||
| - | subtraction | |
| elementwise multiplication | ||
| elementwise power | ||
| division | ||
| > | element maximum | |
| < | element minimum | |
| logical OR | ||
| logical AND | ||
| < | less than | |
| less than or equal to | ||
| > | greater than | |
| greater than or equal to | ||
| ^= | not equal to | |
| equal to | ||
| MOD | modulo (remainder) |
For example, consider the following two matrices
and
:
The addition operator
adds corresponding matrix elements, as follows:
The elementwise multiplication operator
multiplies corresponding elements, as follows:
The elementwise power operator
raises elements to powers, as follows:
The element maximum operator
compares
corresponding elements and chooses the larger, as follows:
The modulo operator returns the remainder of each element divided by the argument, as follows:
All operators can also work in a one-to-many or many-to-one
manner, as well as in an element-to-element manner;
that is, they enable you to perform tasks such as adding
a scalar to a matrix or dividing a matrix by a scalar.
For example, the following statement replaces each negative element of
the matrix
with 0:
x=x#(x>0);
The expression (X>0) is a many-to-one operation that
compares each element of
Copyright © 2009 by SAS Institute Inc., Cary, NC, USA. All rights reserved.