犰狳:将子视图更改为相同的值

Armadillo: changing a subview to the same value

本文关键字:视图 犰狳      更新时间:2023-10-16

我刚刚开始使用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);