문제

Let's say I have two eigen matrices A and B, and I want to create a third matrix defined by

C(i,j) = 5.0 if A(i,j) > B(i,j), 0 otherwise

I guess it is possible to do it without an explicit for loop. But I am not very proficient with Eigen yet. What whould be the best approach?

도움이 되었습니까?

해결책

Assuming A, B and C are MatrixXd you can do:

C = (A.array()>B.Array()).cast<double>() * 5.0;
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top