Eigen C ++中的列式点积 [英] Column-wise dot product in Eigen C++

查看:134
本文介绍了Eigen C ++中的列式点积的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有一种简单的方法可以评估尺寸为mxn的2个矩阵(按其类型为Eigen::MatrixXdAB)的列式点积,而无需评估A*B或不评估不得不求助于for循环?所得的矢量将需要具有1xnnx1的尺寸.另外,我正在尝试使用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屋!

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