Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 445
user2966224 Avatar asked Oct 15 '25 20:10

user2966224


1 Answers

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);
like image 100
mtall Avatar answered Oct 19 '25 11:10

mtall



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!