dimanche 9 juillet 2023

Extract Eigen subarray based on a boolean array

I have two Eigen::VectorXd named xl and xu with the same size. Based on these arrays, I build a boolean array fixed_indices as follows (Given some tolerance tol).

Eigen::Vector<bool, Eigen::Dynamic> fixed_indices = (xl - xu).array().abs() <= tol;

I want to extract the values of xl and xu where fixed_indices is true. In other words, in the Python world (using NumPy), I would do

fixed_values = 0.5 * (xl[fixed_indices] + xu[fixed_indices])

How can I do that with Eigen arrays? Thank you very much for the help!

Aucun commentaire:

Enregistrer un commentaire