简体   繁体   中英

Convert Eigen::ArrayXXd to Eigen::MatrixXd

How do you convert an ArrayXXd array to a MatrixXd ? So far I've done

MatrixXd temp_mat = my_array;

and the implicit conversion seems to work fine, but is this the way it is supposed to be done? Or is there some explicit conversion operation I should be doing?

Yes, implicit conversion is intended to work as you are doing it.

If you want to "view" an Array as a Matrix without actually copying it, you can use the .matrix() method. Eg,

ArrayXXd A;
VectorXd v;

VectorXd r = A.matrix() * v; // matrix vector product

There is an inverse to this method called .array() .

This is described in more detail in the "Converting between array and matrix expressions" section of the tutorial on the Array class .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM