Logical Arrays
Logical arrays in ILNumerics are similar to regular arrays, having elements of type bool. Logicals are created as result of binary comparison operations (
Some examples of the creation of logical arrays:
The same options exist for handling logicals as for other arrays. Logicals can be used as local variable or returned from functions. However, logicals are mostly useful for the selection of elements and can directly be used on both sides of indexing expressions or as arguments of the
An expression
The scheme generalizes to the n-dimensional case. Logicals can be combined with all other common index specifiers for n-dimensional subarray range definitions. On the left side of assignments, logicals are convenient too:
Number of True elements
Logical arrays track the number of their elements evaluating to 'true'. Being mostly an optimization feature the number can also be useful in algorithms: