Logical operators are useful when writing batch files or custom functions. Logical operators,
when com-
bined with flow control, allow for complex choices to be compactly expressed.
11.1
Symbol
Function
Definition
>
greater
Greater than
>=
greater_equal
<
less
Less than
<=
less_equal
==
equal
Equal to
!=
not_equal
Not equal to
Logical operators can be used on scalars, arrays or matrices. All comparisons are done
element-by-
z= x < y will be an array of the same size as broadcast(x,y).shape composed of True and False.
Alter-
natively, if one is scalar, say y, then the elements of z are z[i,j] = x[i,j] < y. For instance, suppose
z = xLy where L is one of the logical operators above such as < or ==. The following table
examines the
Scalar
Array
Scalar
Any
Any
z=x<y
zi j= x < yi j
Array
Any
Broadcastable
zi j= xi j< y
zi j= ˜ xi j< ˜ yi j
tions of programs known as flow control (e.g. if ... else ... blocks) which are be discussed in
Chapter
13. It is important to remember that array logical operations return arrays and that flow
control blo