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;
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)
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; }
Source: https://habr.com/ru/post/943779/More articles:Change sbt output directory - scalaVertical alignment of inline elements with different heights - htmlBoyer-Moore-Horspool algorithm for all matches (find byte array inside Byte array) - c #How to accurately solve quadratic equations with large integer coefficients (for integers)? - pythonOpen Contact Picker with filter - androidFull Screen DialogFragment (over ActionBar) in Android - androidVim syntax syntax for C ++ 11 that won't ruin another highlight. For example, the scope of a class / namespace is c ++Python rpy2 and matplotlib conflict when using multiprocessing - pythonPython multiprocessing error on Mac OS X - pythonPhp 404 Not Found Header - phpAll Articles