特征稀疏矩阵获取非零元素的索引 [英] Eigen Sparse Matrix get Indices of Nonzero Elements
本文介绍了特征稀疏矩阵获取非零元素的索引的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我第一次使用本征稀疏矩阵,现在我想知道如何获取非零元素的索引. 我构造了稀疏矩阵,如下所示:
I am using Eigen Sparse Matrices for the first time, and now I would like to know how to get the indices of the nonzero elements. I constructed my Sparse Matrix as follows:
Eigen::SparseMatrix<Eigen::ColMajor> Am(3,3);
通过查看m_indices变量,我可以看到VS中的一些索引.但是我无法访问它们.谁能帮帮我吗? 对于像
and I can see some indices in VS by looking into the m_indices variable. But I can't access them. Can anyone please help me? For a Matrix like
( 1 0 1
0 1 1
0 0 0 )
我希望索引像(0,0), (0,2), (1,1), (1,2)
.
有什么办法吗?
P.S.我的矩阵比3x3大得多.
P.S. My matrices are way bigger than 3x3.
推荐答案
教程的代码与此类似:
for (int k=0; k < A.outerSize(); ++k)
{
for (SparseMatrix<int>::InnerIterator it(A,k); it; ++it)
{
std::cout << "(" << it.row() << ","; // row index
std::cout << it.col() << ")\t"; // col index (here it is equal to k)
}
}
这篇关于特征稀疏矩阵获取非零元素的索引的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文