如何获得Armadillo C++中的非零位置(索引)数组和稀疏矩阵的值?
到目前为止,我可以很容易地用一组位置(作为umat对象)和值(作为vec对象)来构造稀疏矩阵:
// batch insertion of two values at (5, 6) and (9, 9)
umat locations;
locations << 5 << 9 << endr
<< 6 << 9 << endr;
vec values;
values << 1.5 << 3.2 << endr;
sp_mat X(locations, values, 9, 9);
我怎么才能把地点弄回来?例如,我希望能够做这样的事情:
umat nonzero_index = X.locations()
有什么想法吗?
发布于 2015-03-11 09:06:16
关联的稀疏矩阵迭代器具有.row()
和.col()
函数:
sp_mat::const_iterator start = X.begin();
sp_mat::const_iterator end = X.end();
for(sp_mat::const_iterator it = start; it != end; ++it)
{
cout << "location: " << it.row() << "," << it.col() << " ";
cout << "value: " << (*it) << endl;
}
https://stackoverflow.com/questions/28980228
复制相似问题