1

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?

chtz
  • 17,329
  • 4
  • 26
  • 56
Juan Carlos Ramirez
  • 2,054
  • 1
  • 7
  • 22

1 Answers1

2

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. E.g.,

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.

chtz
  • 17,329
  • 4
  • 26
  • 56