I know that in Eigen I can use unaryExpr()
to apply a custom function to my Eigen Matrices and Vectors, e.g.
Eigen::VectorXd vec(4);
vec.unaryExpr([](double d) {
return d * cos(d);
});
to apply custom functions to a Eigen::VectorXd
. But is there also a way to get the position of the current element in my Vector? I want to be able to do something like this:
Eigen::VectorXd vec(4);
vec.unaryExpr([](double d, int index) {
return index * d;
});
which would for example multiply each entry in the vector by it's position.