Eigen C ++中的列式点积 [英] Column-wise dot product in Eigen C++
本文介绍了Eigen C ++中的列式点积的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有一种简单的方法可以评估尺寸为mxn
的2个矩阵(按其类型为Eigen::MatrixXd
的A
和B
)的列式点积,而无需评估A*B
或不评估不得不求助于for
循环?所得的矢量将需要具有1xn
或nx1
的尺寸.另外,我正在尝试使用C ++中的Eigen做到这一点
Is there an easy way to evaluate the column wise dot product of 2 matrices (lets call them A
and B
, of type Eigen::MatrixXd
) that have dimensions mxn
, without evaluating A*B
or without having to resort to for
loops? The resulting vector would need to have dimensions of 1xn
or nx1
. Also, I'm trying to do this with Eigen in C++
推荐答案
有很多方法可以实现此目的,并且都执行惰性评估:
There are many ways to achieve this, all performing lazy evaluation:
res = (A.array() * B.array()).colwise().sum();
res = (A.cwiseProduct(B)).colwise().sum();
我的最爱:
res = (A.transpose() * B).diagonal();
这篇关于Eigen C ++中的列式点积的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文