Coefficient-wise custom functions in Eigen

倖福魔咒の 提交于 2019-12-05 03:02:03

You can use unaryExpr, though this returns a new view onto the matrix, rather than allowing you to modify the elements in place.

Copying the example out of the documentation:

double ramp(double x)
{
  if (x > 0)
    return x;
  else 
    return 0;
}
int main(int, char**)
{
  Matrix4d m1 = Matrix4d::Random();
  cout << m1 << endl << "becomes: " << endl << m1.unaryExpr(ptr_fun(ramp)) << endl;
  return 0;
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!