Ask Your Question
0

how can i "reshape" a matrix 4d to matrix 2d and vice versa?

asked 2017-07-24 06:00:25 -0600

Alvaro gravatar image

i have a matrix vector<vector<mat>> with [256][20][10][10] dimensions and i want to convert this in a Mat matrix with [2000][256] dimensions. Thanks for all.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2017-07-24 06:22:08 -0600

berak gravatar image

needs quite some shuffeling, but doable:

vector<vector<mat>> vvm = ...
Mat res; // initially empty

for (size_t i=0; i<vvm.size(); i++) {
    Mat row; // empty
    for (size_t j=0; j<vvm[0].size(); j++) {
        Mat m = vvm[i][j];
        row.push_back(m.resize(1,1)); // 1 x 100
    }
    res.push_back(row.reshape(1,1)); //1 x 2000
}
edit flag offensive delete link more

Comments

Thank you so much!!!

Alvaro gravatar imageAlvaro ( 2017-07-25 03:31:28 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2017-07-24 06:00:25 -0600

Seen: 823 times

Last updated: Jul 24 '17