犰狳:将子视图更改为相同的值
Armadillo: changing a subview to the same value
我刚刚开始使用Armadillo,我正试图将向量中的一些值更改为相同的值。我知道改成0或1很容易。
为什么最后一行不能工作?我所发现的唯一方法要复杂得多。
arma::vec x = arma::linspace<arma::vec>(1, 20, 10);
std::cout << x << std::endl;
x(arma::find(x > 15)).ones();
std::cout << x << std::endl;
x(arma::find(x < 6)) = arma::datum::nan; // this doesn't compile
//这就是我如何得到它的工作,但有没有更好的方法?
arma::uvec idx = find(x < 6);
arma::vec idxrepl(idx.n_elem);
idxrepl.fill(arma::datum::nan);
x.elem(idx) = idxrepl;
std::cout << x << std::endl;
谢谢
尝试:
x(arma::find(x < 6)).fill(arma::datum::nan);
相关文章:
- 犰狳C++ - 从常量内存初始化只读矩阵而不复制
- 在原子中使用犰狳与脚本
- 犰狳的 print() 方法和 cout 在从 Rcpp 调用时顺序不一致
- 方括号 [] 和括号 () 之间的犰狳库差异
- C++ 犰狳库中的sort_index()函数给出了错误的结果
- 犰狳C++:带有模量计算的线性组合
- Python/C++:可以导入犰狳(arma::)但不能导入子程序arma::arma_rng::randn
- 无法使用犰狳运行编译的 cpp 代码,因为 dyld:库未加载
- 犰狳相当于 A(find(A<0)) = 0
- 犰狳(C++)中的快速阵列置换(广义张量转置)
- 犰狳代码无法在 msys2 和 netbeans 中编译
- C++:犰狳不想与hdf5格式合作
- C++犰狳重塑了一个只有一个维度大小的矩阵
- <int> 与垫子<int>相比,犰狳SpMat非常慢
- 在犰狳立方体中添加一列 1 的有效方法
- 使用犰狳时无法加载犰狳立方体<uword>
- 两个向量在犰狳中相等?
- 犰狳:将立方体子视图(管)转换为矢量
- 犰狳:arma::subview的非连续视图
- 犰狳:将子视图更改为相同的值