Pergunta

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,

Foi útil?

Solução

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));
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top