Using the C++ Math Library | ![]() ![]() |
Relational Operators
The relational operators compare two arrays and return an identically sized array of 1's and 0's with the logical flag set. They perform an element-wise comparison of their inputs. The operators work as follows: given an expression C = (A op B)
, where op
is one of the operators below, then C[i] == 1
if(A[i] op B[i])
is true and C[i] == 0
otherwise.
For example, if A
is the matrix [ 1 2 ; 3 4 ]
and B
is the matrix[ 0 2 ; 1 6 ]
, then A > B
is [ 1 0 ; 1 0 ]
. The result contains 1's where the greater-than relationship between the corresponding elements of A
and B
is true, and the result contains 0's where it is false. The result of a relational operation is a logical array.
Using Logical Subscripts in Chapter 4 provides information on logical indexing.
![]() | Arithmetic Operators | Miscellaneous Operators | ![]() |