Eigen Boolean Array Sorting

In MATLAB, it is customary to trim values ​​that satisfy some condition from a matrix / array (called logical indexing ).

vec = [1 2 3 4 5]; condition = vec > 3; vec(condition) = 3; 

How to do it in Eigen? So far, I:

 Eigen::Matrix<bool, 1, 5> condition = vec.array() > 3; 
+6
source share
2 answers

As stated in an answer to a similar question: Submatrices and indexes using Eigen , libigl adds this function to Eigen.

 igl::slice(A,indices,B); 

Is equivalent

 B = A(indices) 
0
source

Try this :

 #include <iostream> #include <Eigen/Dense> int main() { Eigen::MatrixXi m(1, 5); m << 1, 2, 3, 4, 5; m = (m.array() > 3).select(3, m); std::cout << m << std::endl; return 0; } 
+9
source

Source: https://habr.com/ru/post/943779/


All Articles