How do you initialize a boolean array in the Eigen library (C++) to a specific truth value? There are initializers for numeric matrices but I can't find an example for a boolean array (Eigen::Array).
The other answer are correct, but for completeness let me add:
#include <Eigen/Dense>
using namespace Eigen;
typedef Array<bool,Dynamic,1> ArrayXb;
ArrayXb a = ArrayXb::Constant(5,true);
ArrayXb b(5);
b.setConstant(true); // no-resizing
b.fill(true); // alias for setConstant
b.setConstant(10,true); // resize and initialize
Array<bool, 5, 1> c(true);
In the last case, because here the size is known at compile time, the argument is interpreted as the initializing value.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With