Previous: User et, Up: Array Expressions [Contents][Index]
Blitz++ provides the where function as an array expression version of the
( ? : ) operator. The syntax is:
where(array-expr1, array-expr2, array-expr3)
Wherever array-expr1 is true, array-expr2 is returned. Where
array-expr1 is false, array-expr3 is returned. For example,
suppose we wanted to sum the squares of only the positive elements of an
array. This can be implemented using a where function:
double posSquareSum = sum(where(A > 0, pow2(A), 0));