将二维数组转换为犰狳矩阵mat对象

问题描述

如何将标准 C++ 2D 数组转换为表示矩阵的 Armadillo mat 对象,以便我可以执行矩阵运算?

例如,我想转换自:

double a[10][20];

到:

arma::mat A;

解决方法

使用

arma::mat A(&a[0][0],10,20);

如果您想要缓冲区的副本并且:

arma::mat A(&a[0][0],20,false);

如果你想使用 a 指出的缓冲区,更多详细信息参见 http://arma.sourceforge.net/docs.html#Mat

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...