matrixcubereshapearmadillo

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


Solution

  • 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);