开发者

vector into matrix armadillo

开发者 https://www.devze.com 2023-03-20 03:43 出处:网络
I want to do something similar to MATLAB\'s function: mat = vec2mat(vec,matcol) mat = vec2mat(vec,matcol,padding)

I want to do something similar to MATLAB's function:

mat = vec2mat(vec,matcol)
mat = vec2mat(vec,matcol,padding)
[mat,padded] = vec2mat(...) 

but in armadillo c++ library,开发者_如何学Go Do you know How?.


It shouldn't be so hard to achieve similar behavior with reshape I think:

mat vec2mat(vec V, size_t cols) {
    size_t rows = std::ceil(V.n_elems / double(cols));
    return V.reshape(cols, rows);// return the original vector as matrix
}

It's not exactly the same (it padds always with 0), but it's quite similar I think.

0

精彩评论

暂无评论...
验证码 换一张
取 消