繁体   English   中英

从矩阵列中减去特征向量

[英]Eigen subtracting vector from matrix columns

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

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

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()但是没有用。

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

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)

您要对多个数据(SIMD)使用一条指令。 您可以尝试使用向量计算,例如Intel的AVX: https//software.intel.com/sites/landingpage/IntrinsicsGuide/

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM