使用Rcpp删除矩阵行时出现错误 [英] Get error when use Rcpp remove rows of matrix
本文介绍了使用Rcpp删除矩阵行时出现错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
#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);
}
只想从矩阵中删除一些行,得到如下错误.从无效"到非标量类型"arma :: Mat}的转换"
Just want remove some rows from matrix, get error as follows. conversion from 'void' to non-scalar type 'arma::Mat} requested'
推荐答案
两点:
- 请不要将错误消息发布为图像.请改用文字".
- 如错误所示,
shed_rows()
方法不返回任何内容.取而代之的是,它改变了作用的矩阵,参见文档.
- Please don't post error messages as image. Use Text instead.
- As the error indicates, the
shed_rows()
method does not return anything. Instead it alters the matrix it acts on, 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))
*/
这篇关于使用Rcpp删除矩阵行时出现错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文