【问题标题】:Get error when use Rcpp remove rows of matrix使用 Rcpp 删除矩阵行时出错
【发布时间】:2018-09-14 05:30:35
【问题描述】:
#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} 请求'

【问题讨论】:

  • 请不要发布屏幕截图。这样做没有充分的理由,而且您可以更轻松地复制文本。

标签: r rcpp armadillo


【解决方案1】:

两点:

  • 请不要将错误消息作为图片发布。请改用文本。
  • 如错误所示,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))
*/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-03-01
    • 1970-01-01
    • 2017-03-21
    • 1970-01-01
    • 2021-11-14
    • 2013-09-23
    • 1970-01-01
    相关资源
    最近更新 更多