我在 C++ 中使用 Eigen 中的稀疏矩阵工作。我想读取存储在特定行和列索引中的数据,就像使用常规特征矩阵一样。
std::vector<Eigen::Triplet<double>> tripletList;
// TODO: populate triplet list with non-zero entries of matrix
Eigen::SparseMatrix<double> matrix(nRows, nCols);
matrix.setFromTriplets(tripletList.begin(), tripletList.end());
// TODO: set iRow and iCol to be valid indices.
// How to read the value at a specific row and column index?
// double value = matrix(iRow, iCol); // Compiler error
我该如何执行这种类型的索引操作?
原文由 MattKelly 发布,翻译遵循 CC BY-SA 4.0 许可协议
试试
coeff
:如果您想要一个非常量版本,请改用
coeffRef
。请注意,使用coeffRef
时,如果该元素不存在,它将被插入。