Вопрос

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