Armadillo - 如何从稀疏格式创建矩阵?

Armadillo - how to create Matrix from sparse format?

假设我有一个稀疏矩阵。我将其定义为以下 CSV 格式:

row,column,value 1,1,5 1,2,10

在这种情况下,点(1,1)等于5,点(1,2)等于10。

根据这种格式(假设有数千或数十万行)创建矩阵的有效方法是什么?

换句话说,我想要在 Matlab 中相当于 运行 full(spconvert(m)),其中 m 是上面的矩阵。

您需要使用 sp_mat 稀疏矩阵 class 的批量插入构造函数之一。在 documentation:

中有一个如何做的例子
// 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);