Get indices where an integer array is non-zero
Array_Type where (Array_Type a)
The where
function examines an integer array a
and
returns a 2-d integer array whose rows are the indices of a
where the corresponding element of a
is non-zero.
Consider the following:
variable X = [0.0:10.0:0.01];
variable A = sin (X);
variable I = where (A < 0.0);
A[I] = cos (X) [I];
Here the variable X
has been assigned an array of doubles
whose elements range from 0.0
through 10.0
in
increments of 0.01
. The second statement assigns A
to
an array whose elements are the sin
of the elements of X
.
The third statement uses the where function to get the indices of
the elements of A
that are less than 0.0
. Finally, the
last statement substitutes into A
the cos
of the
elements of X
at the positions of A
where the
corresponding sin
is less than 0
. The end result is
that the elements of A
are a mixture of sines and cosines.
array_info, sin, cos