请问cpp里的eigen库怎么像matlab或者python一样取出矩阵的一部分,比如某一行或者某一列,能不用循环吗?
当然可以,如下:
1.通过行或列索引提取子矩阵:
#include <Eigen/Dense>
int main() {
Eigen::MatrixXd matrix(3, 3);
matrix << 1, 2, 3,
4, 5, 6,
7, 8, 9;
Eigen::VectorXd row = matrix.row(1); // 提取第二行
Eigen::VectorXd col = matrix.col(0); // 提取第一列
return 0;
}
2.使用区块操作提取子矩阵:
```c++
#include <Eigen/Dense>
int main() {
Eigen::MatrixXd matrix(3, 3);
matrix << 1, 2, 3,
4, 5, 6,
7, 8, 9;
Eigen::MatrixXd submatrix = matrix.block(0, 1, 2, 2); // 提取第一行和第二行,第二列和第三列构成的子矩阵
return 0;
}
```
如果可以的话,请采纳