Registered Member
|
Hi,
Is there an efficient way to "clip" an Eigen array? I.e. to set all values above a given threshold to this threshold? |
Registered Member
|
a = a.max(0.5); // threshold is 0.5, a is an array; use .cwiseMax() instead of .max() for matrices
|
Registered Member
|
Thanks for the quick reply! When I was scrolling through the docs I saw that function, but I was erroneously dismissing it, thinking it was the maximum value of the Matrix. For the problem I described above, I would actually need a = a.min(0.5); Before your answer, I was trying to cook up an alternative which is not nearly as elegant as min(), but which illustrates the use of unaryExpr() with lambda functions, so I'll give it anyway in case it might be useful for someone else.
|
Registered users: Bing [Bot], Google [Bot], Yahoo [Bot]