I want to reshape a 2D matrix into a 3D matrix and then stack on this 3D matrix; I have tried to do this as below code:
let multi_num = 2;
let kline_re = ndarray::arr2(&[[1,2], [3, 4], [5, 6], [7, 8], [9, 10], [11, 12]]);
let kd_shape = kline_re.shape();
let kline_re_3 = kline_re.to_shape(((kline_re.shape()[0] / multi_num, multi_num, kd_shape[1]), Order::RowMajor)).unwrap();
let mut kline_re_splits = vec![];
for i in 0..kline_re_3.shape()[0] {
kline_re_splits.push(kline_re_3.slice(ndarray::s![i, .., ..]));
}
let x = ndarray::stack(Axis(1), &kline_re_splits).unwrap();
println!("{:#?}", x);
the final result looks like this:
[[[1, 2],
[5, 6],
[9, 10]],
[[3, 4],
[7, 8],
[11, 12]]], shape=[2, 3, 2], strides=[2, 4, 1], layout=c (0x4), const ndim=3
but I don't know how to convert it into a Vec and I think above code is too fussy(I mean maybe there should be more elegant method). so it is really appreciated for any advice.