简体   繁体   中英

Element wise inversion in Eigen Matrix

Is there a function/s for doing elementwise inversion of an Eigen Matrix

#include <eigen3/Eigen/Dense>

const auto mat = Eigen::MatrixXd::Constant(3, 3, 5);
std::cout << mat;

5 5 5
5 5 5
5 5 5

And my expected result is this:

1/5 1/5 1/5
1/5 1/5 1/5
1/5 1/5 1/5

Is there any other way to do this apart from using a for-loop? (Also, will using a for loop on eigen matrix for scalar operations be slower as compared to matrix operations)

Solved this issue. Just putting here in case anyone else comes across this issue

mat.cwiseInverse()

Link to all co-efficient wise functions for eigen

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM