【发布时间】:2019-06-15 00:46:15
【问题描述】:
我有一个矩阵 X,它由 arma::vectorise 函数向量化。在对转换后的向量 x 进行一些计算之后,我想将其重塑为 arma::mat。我尝试在犰狳中使用.reshape 函数,但它给了我这个错误。
Rcpp 代码
// [[Rcpp::export]]
arma::mat vec2mat(arma::vec x, int nrow, int ncol){
return x.reshape(nrow, ncol);
}
错误信息
no viable conversion from returned value of type 'void' to function return type 'arma::mat' (aka 'Mat<doubld>')
有人能帮我找到处理这个问题的好方法吗?我不确定在这种情况下我应该为函数返回类型使用什么类型。如果您知道另一种将向量转换为矩阵的方法,那也很棒:)
提前致谢!
【问题讨论】:
-
不使用.reshape()成员函数(前面有一个点),而是使用单机版:reshape()。不需要使用上面的 vec2mat() 函数。
标签: r type-conversion rcpp