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