Eigen: mask an array

前端 未结 2 1065
萌比男神i
萌比男神i 2021-02-20 15:14

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         


        
相关标签:
2条回答
  • 2021-02-20 16:09

    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)
    
    0 讨论(0)
  • 2021-02-20 16:15

    I found some reference here http://igl.ethz.ch/projects/libigl/matlab-to-eigen.html

    For B = IM(A), they suggest:

    B = A.unaryExpr(bind1st(mem_fun( 
        static_cast<VectorXi::Scalar&(VectorXi::*)(VectorXi::Index)>
        (&VectorXi::operator())), &IM)).eval();
    

    But it's not a generalized solution (and actually I couldn't try it )

    0 讨论(0)
提交回复
热议问题