Eigen矩阵/向量操作
应知应会
- Eigen中矩阵和向量相加,没有Python中的广播机制
- Eigen中的索引时是小括号
()
而不是方括号[]
,不同于python中的numpy
参考资料
- 官网文档:https://eigen.tuxfamily.org/dox/group__TutorialMatrixArithmetic.html
- 中文博客:https://blog.csdn.net/u012936940/article/details/79782068
Block操作
Eigen::MatrixXf m(4,4);
m << 1, 2, 3, 4,
5, 6, 7, 8,
9,10,11,12,
13,14,15,16;
std::cout << "Block in the middle" << std::endl;
std::cout << m.block<2,2>(1,1) << std::endl << std::endl;
for (int i = 1; i <= 4; ++i)
{
std::cout << "Block of size " << i << "x" << i << std::endl;
std::cout << m.block(0,0,i,i) << std::endl << std::endl;
}
// Eigen::Vector2f vec(1, 2);
// std::cout << "vector.norm(): " << vec.norm() << std::endl;
// vector.norm(): 2.23607
In the above example the .block() function was employed as a rvalue, i.e. it was only read from. However, blocks can also be used as lvalues, meaning that you can assign to a block.
参考资料
https://eigen.tuxfamily.org/dox/group__TutorialBlockOperations.html