1
如何将动态矩阵的列增加1,作为就地操作(不创建副本/中间体)?本征增量一列
尝试:
#include <Eigen/Dense>
#include <iostream>
#include <stdint.h>
int main(void){
Eigen::MatrixXf A;
A = Eigen::MatrixXf::Random(3, 5);
std::cout << A << std::endl << std::endl;
A.col(1) = A.col(1)*2; //this works.
A.col(1) = A.col(1) + 1; //this doesn't work.
std::cout << A << std::endl;
}
使用'阵列()'方法是什么,我会推荐。如果您主要在做元素操作,请考虑从头开始将'A'存储为'Eigen :: ArrayXXf'。稍后您仍然可以通过'matrix()'方法访问'A'作为矩阵。 – chtz