Eigen: mask an array

c++, eigen

Solution

From the Quick Reference

(R.array() < s).select(P,Q);  // (R < s ? P : Q)

so, in your case it would be

(arrayA > 5).select(mask, arrayA)

Problem

Is it possible to mask an array in Eigen as in Matlab? Something like ``` ArrayXd arrayA = ArrayXd::Random(10, 5); ArrayXi mask = ArrayXi::Zero(arrayA.rows(), arrayA.cols()); mask = arrayA > 5; ArrayXd arrayB = arrayA(mask) ``` where arrayB is a row vector containing all and only the elements of arrayA>5 I could find similar requests but not any updated answer after 2011 ( https://forum.kde.org/viewtopic.php?f=74&t=98382 , https://forum.kde.org/viewtopic.php?f=74&t=98093 , https://forum.kde.org/viewtopic.php?f=74&t=97652)

Original source