Question

I have a Sparse matrix and I would like to initialize an Array from it.

Is there something better and more "compact" than a for cycle? I'm looking for something like:

SparseMatrix<float, RowMajor> SpM;
ArrayXf Af;
Af = Arrayf(SpM.row(1));

Thanks in advance,

Was it helpful?

Solution

What you wrote is almost correct. The only subtle difference to make it work is to first construct a dense VectorXf before moving to the array world:

SparseMatrix<float,RowMajor> mat;
ArrayXf Af;
Af = VectorXf(mat.row(1));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top