矩阵列的本征减法向量 [英] Eigen subtracting vector from matrix columns

查看:61
本文介绍了矩阵列的本征减法向量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

矩阵 linesP0 为3xN.我想从向量 planeP0 减去3x1.有没有更聪明,更快捷的方法来做到这一点?

Matrix linesP0 is 3xN. I want to subtract it from vector planeP0 which is 3x1. Is there any smarter and faster way to do this?

现在我正在使用for循环.下面的示例代码:

Now I'm using a for loop. Sample code below:

MatrixXf temp(linesP0.rows(), linesP0.cols());
for (int i = 0; i < linesP0.cols(); i++)
{
    temp.col(i) = planeP0 - linesP0.block<3, 1>(0, i);
}

我尝试使用 colwise(),但是没有用.

I tried to use colwise() but didn't work.

推荐答案

您可以使用.colwise()来做到这一点,只需要一点点创意即可.

You can use .colwise() to do this, you just have to be a little creative.

Vector3d v      = Vector3d(1.0, 2.0, 3.0);
Matrix3d m      = Matrix3d::Random();
Matrix3d result = (-m).colwise() + v;
std::cout << result << std::endl;

抽样结果:

v = [1 2 3]' (3x1)
m = [1 1 1; 2 2 2]' (3x2)
result = [0 1 2; -1 0 1]' (3x2)

这篇关于矩阵列的本征减法向量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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