Column-wise dot product in Eigen C++

前端 未结 3 2000
不知归路
不知归路 2021-01-12 14:43

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

3条回答
  •  暖寄归人
    2021-01-12 14:56

    There are many ways to achieve this, all performing lazy evaluation:

    res = (A.array() * B.array()).colwise().sum();
    res = (A.cwiseProduct(B)).colwise().sum();
    

    And my favorite:

    res = (A.transpose() * B).diagonal();
    

提交回复
热议问题