Mohammadrezamc2
Mohammadrezamc2

Reputation: 11

Convert a 2D array into an Armadillo matrix (mat) object

How do I convert a standard C++ 2D array into an Armadillo mat object representing a matrix, so that I can perform matrix operations?

For example, I want to convert from:

double a[10][20];

to:

arma::mat A;

Upvotes: 0

Views: 862

Answers (1)

Claes Rolen
Claes Rolen

Reputation: 1466

Use

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

if you want a copy of the buffer and:

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

if you want to use the buffer pointed out by a, for more detailed information see http://arma.sourceforge.net/docs.html#Mat

Upvotes: 3

Related Questions