Question

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

Was it helpful?

Solution

Try something along these lines:

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);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top