mardi 4 août 2015

Is there an easy way to transform a tensor (3D array) to a 2D array of the tensor slices as the vectors in MATLAB?

Consider a 3D matrix t of size d1 x d2 x d3. Is there a an easy way of making the matrix (2D array) of size d1d2 x d3?

so the naive implementation/pseudo-code would be something like:

T % d1 x d2 x d3
M % d1d2 x d3
for i=1:d3
    t_slice = t(:,:,i);
    m = reshape(t_slice, [d1d2, 1]); %columns of t_slice are the vector
    M(:,i) = m;
end

but it seemed something that should already be implemented or some library in matlab that already does this. Doing this by hand seems a little inefficient and I was suspecting that there was some clever MATLAB trick to do this. Am I right?

Ideally I thought something like:

M = reshape(T,[d1d2, d3])

would exist, but wasn't sure or couldn't find it yet...



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire