- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
是否有一种有效的方法可以只保留 Armadillo 稀疏矩阵的行,这些行总和至少达到矩阵各列的总计数水平?例如,我想保留第 i
行,如果它的值的总和是 >=C
,其中 C
是一些选择值(value)。 Armadillo 的文档说稀疏矩阵只允许连续的子矩阵 View 。所以我猜这不容易通过子设置获得。除了简单地遍历元素并创建一个具有新位置、值和 colPtr 设置以匹配所需条件的新稀疏矩阵之外,是否有替代方法?谢谢!
最佳答案
执行速度最快的解决方案很可能就是您提出的解决方案。如果您想利用高级 Armadillo 功能(即编码速度更快但运行速度可能更慢),您可以构建一个包含“坏”行 ID 的 std::vector
然后使用 shed_row(id)
。删除行时注意索引。这是通过始终从矩阵底部脱落来实现的。
auto mat = arma::sp_mat(rowind, colptr, values, n_rows, n_cols)
auto threshold_value = 0.01 * arma::accu(sp_mat); // Sum of all elements
std::vector<arma::uword> bad_ids; // The rows that we want to shed
auto row_sums = arma::sum(mat); // Row sums
// Iterate over rows in reverse order.
for (const arma::uword row_id = mat.nrows; i-- > 0; ) {
if (row_sum(row_id) < threshold_value) {
bad_ids.push_back(row_id);
}
}
// Shed the bad rows from the bottom of the matrix and up.
for (const auto &bad_id : bad_ids) {
matrix.shed_row(bad_id);
}
关于c++ - 如何根据行总计的条件在 Armadillo 中删除 SpMat<unsigned int> 的行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42849350/
我想知道如何遍历 sp_umat 的所有非零条目(即 SpMat )在 Armadillo 中,并遇到了这个相关问题( link )。该帖子建议使用 const_iterator检索 sp_mat 中
我正在使用 Armadillo C++ 线性代数库,我正在尝试弄清楚如何将 sp_mat 转换为稀疏矩阵对象到标准 mat稠密矩阵。 查看 internal code doc , sp_mat和 ma
是否有一种有效的方法可以只保留 Armadillo 稀疏矩阵的行,这些行总和至少达到矩阵各列的总计数水平?例如,我想保留第 i 行,如果它的值的总和是 >=C,其中 C 是一些选择值(value)。
我正在尝试在 Armadillo 中使用稀疏矩阵,并且注意到 SpMat 的访问时间存在显着差异与使用 Mat 的等效代码相比. 描述: 下面是两种方法,除了Method_One 之外,它们在各个方面
这是上一个问题的延续 - 主要围绕 Armadillo C++ 库中对 SpMat(或 sp_mat)的支持。 尝试求逆稀疏矩阵时,出现编译错误 error: no matching function
我是一名优秀的程序员,十分优秀!