Comparing two matrices with eigen

自闭症网瘾萝莉.ら 提交于 2019-12-12 09:56:40

问题


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?


回答1:


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

C = (A.array()>B.Array()).cast<double>() * 5.0;


来源:https://stackoverflow.com/questions/22228332/comparing-two-matrices-with-eigen

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!