c++ - 访问 UBLAS 稀疏 vector 中非零元素的索引

标签 c++ boost sparse-matrix ublas

我如何知道 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/

相关文章:

C++ OpenGL 着色版本错误 - 不支持 GLSL x [Ubuntu 16.04]

c++ - 了解 C++ 中的删除

java - 将标签(对象名称)添加到实例对象

c++ - 'auto_ptr' 和 STL 容器 : writing an example of erroneous usage

c++ - 没有对 std::index_sequence 中的包扩展进行诊断

c++ boost MPI & threading - 序列化错误 : Address not mapped

python - python和C++之间的通信

c++ - 修改系统时钟时,boost::deadline_timer 可能会失败

matlab - 在 MATLAB 中查找大型稀疏矩阵的零空间

CHOLMOD 稀疏矩阵 cholesky 分解 : incorrect factor?