This is the basic C++ program of C++ armadillo library which returns true if vector V satisfies a relational condition. It can be carried out by the help of inbuilt function "any"in armadillo library.
For vector V, return true if any element of the vector is non-zero or satisfies a relational condition
For matrix X and
dim=0, return a row vector (of type urowvec or umat), with each element (0 or 1) indicating whether the corresponding column of X has any non-zero elements
dim=1, return a column vector (of type ucolvec or umat), with each element (0 or 1) indicating whether the corresponding row of X has any non-zero elements
The dim argument is optional; by default dim=0 is used
Relational operators can be used instead of V or X, eg. A > 0.9
vec V = randu<vec>(10);
mat X = randu<mat>(5,5);
// status1 will be set to true if vector V has any non-zero elements
bool status1 = any(V);
// status2 will be set to true if vector V has any elements greater than 0.5
bool status2 = any(V > 0.5);
// status3 will be set to true if matrix X has any elements greater than 0.6;
// note the use of vectorise()
bool status3 = any(vectorise(X) > 0.6);
// generate a row vector indicating which columns of X have elements greater than 0.7
umat A = any(X > 0.7);
cout << "Vector V::\n"<<endl; cout<< V << endl;
cout << "Matrix X::\n"<<endl; cout << X << endl;
cout << "Status 1::\n"<<endl; cout<< status1 << endl;
Comments