Search code examples
matrixeigeneigen3

How do you get the mean of a Eigen::MatrixXd column?


I know that the functions colwise() and rowwise() exist in Eigen.

I saw this example here in Stack Overflow on how to get the mean of a row using Eigen. However, it is not working for me.

Could somebody please clarify for me on how to get the mean of a particular row or column?

e.g. the 3rd row,

e.g. the 2nd column

Thanks a lot! Have a wonderful day!


Solution

  • Same as with the colwise/rowwise but on a single column/row:

    MatrixXd mat(...);
    // Fill the matrix
    double meanCol3 = mat.col(3).mean();
    double meanRow2 = mat.row(2).mean();