Basic question from a newcomer to Armadillo and C++ from R.
I have a vector X
and I want to set the entries below 0
to a given value and the ones larger than 0
to another. Armadillo has the find
function for returning indices of elements of X that are non-zero or satisfy a relational condition (not logical!?) so I can do:
arma::uvec ind0 = find(X < 0);
arma::uvec ind1 = find(X >= 0);
X(ind0).zeros();
X(ind1).fill(1);
This is clearly not the best solution. What would be a better way that does not involve calling find
two times?