I have a Eigen::MatrixXf mat that has size of 113(rows) X 2009(cols); I am trying to subtract the max of each of its column from each of its column. Here is my code:
VectorXf minVal = mat.colwise().minCoeff(); // mat is MatrixXf
mat.colwise() -= minVal;
Here is the error message:
Assertion failed: dst.rows() == src.rows() && dst.cols() ==
src.cols(), file
C:\cui\Projects\eigen-3.4.0\Eigen\src\Core\AssignEvaluator.h, line 754
Can anyone give a pointer? Thanks a lot.
>Solution :
mat.colwise().minCoeff() returns a row vector (you can assign this to a column vector, because in most cases Eigen implicitly transposes row vectors to column vectors and vice versa).
You should store the result as a Eigen::RowVectorXf and then subtract that from each row, i.e., mat.rowwise() -= minVal;
This should work:
Eigen::RowVectorXf minVal = mat.colwise().minCoeff();
std::cout << mat << "\n\n" << minVal << "\n\n";
mat.rowwise() -= minVal;
std::cout << mat << "\n\n";