将两个矩阵与本征进行比较 [英] Comparing two matrices with eigen

查看:87
本文介绍了将两个矩阵与本征进行比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有两个本征矩阵A和B,并且我想创建一个第三矩阵,定义为

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,如果A( i,j)> B(i,j),否则为0

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

我想没有显式的for循环也可以这样做。但是我对Eigen并不是很熟练。谁是最好的方法?

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?

推荐答案

假设 A B C MatrixXd ,您可以执行以下操作:

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

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

这篇关于将两个矩阵与本征进行比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆