我如何知道 ublas 中 sparse_vector 中的第一个非零元素以及每个后续非零元素的索引?函数 begin() 给了我一个迭代器,它可以用来知道存储的第一个非零值,而不是它在 vector 中的索引。
最佳答案
这是来自 ublas 主要列表的 Oswin Krause 之后的答案:
Iterators offer a method index() which returns the desired result. But remember that only the const_iterator is really sparse!
for(SparseVector::const_iterator pos = sparseVec.begin(); pos != sparseVec.end();++pos){ std::cout << pos.index()<< " "<< *pos; }
关于c++ - 访问 UBLAS 稀疏 vector 中非零元素的索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7501996/