简体   繁体   中英

Eigen: How to extract a row from a Sparse Matrix in an Array

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,

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));

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