代码之家  ›  专栏  ›  技术社区  ›  Xia.Song

使用Rcpp删除矩阵行时出错

  •  0
  • Xia.Song  · 技术社区  · 7 年前
    #include <RcppArmadillo.h>
    // [[Rcpp::depends(RcppArmadillo)]]
    using namespace Rcpp;
    // [[Rcpp::export]]
    arma::mat fed(arma::mat x){
    arma::mat zz=x.shed_rows(0,2);
    return(zz);
    }
    

    只是想从矩阵中删除一些行,得到如下错误。 已请求从“void”转换为非标量类型“arma::Mat}”

    1 回复  |  直到 7 年前
        1
  •  5
  •   Ralf Stubner    7 年前

    两点:

    • 请不要以图片形式发布错误消息。改用文本。
    • shed_rows() 方法不返回任何内容。相反,它改变了它所作用的矩阵c.f。 the documentation .

    以下工作:

    #include <RcppArmadillo.h>
    // [[Rcpp::depends(RcppArmadillo)]]
    using namespace Rcpp;
    // [[Rcpp::export]]
    arma::mat fed(arma::mat x){
        x.shed_rows(0,2);
        return(x);
    }
    
    /*** R
    fed(matrix(1:16, 4 ,4))
    */