user2966224
user2966224

Reputation: 63

How to reshape a cube to a matrix armadillo

do you know if with Armadillo library it is possible to reshape a Cube to a matrix, like in matlab, with a single instruction:

A = reshape(A,M*N,D); , where A was and now it is

thanks a lot

Upvotes: 4

Views: 2442

Answers (1)

mtall
mtall

Reputation: 3620

Try the following code:

cube A = randu<cube>(5,4,3);

// method 1: 
A.reshape(5*4, 3, 1);
mat B = A.slice(0);

// method 2:
mat C = reshape( mat(A.memptr(), A.n_elem, 1, false), 5*4, 3);

Upvotes: 8

Related Questions