Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to replace NaN from armadillo matrix?

What is the armadillo/c++ equivalent for the following matlab code?

A(isnan(A))=b;
like image 242
Clement D. Avatar asked Dec 08 '22 22:12

Clement D.


1 Answers

Use the .transform() member function to change only the NaN entries. This is also faster than using find_nonfinite() and it will leave any Inf values unchanged.

A.transform( [](double val) { return (std::isnan(val) ? double(b) : val); } );
like image 166
hbrerkere Avatar answered Dec 26 '22 00:12

hbrerkere