MATLAB find() / Numpy nonzero idioms for Eigen

前端 未结 3 445
盖世英雄少女心
盖世英雄少女心 2021-02-06 16:36

Chances are this is a very stupid question but I spent a pretty absurd amount of time looking for it on the documentation, to no avail.

in MATLAB, the find() function gi

3条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-06 17:28

    This might work for you and others who check this out. In order to set elements of a matrix m based on the condition on another matrix A, you can use this notation:

    m = (A.array() != 0).select(1, m);
    

    This command replaces those elements in matrix m that have non-zero corresponding elements in A, with one.

提交回复
热议问题