Transpose matrix

I am looking for functionality compared to opencv's transpose where the axes of a multidimensional array are easily swapped (an (640, 400, 3) style image to a (3, 640, 400) image).

I prefer to use existing functionality instead of cooking it up myself ( if needed I do it). Does the ndarray crate offers me such functionality ?

https://nalgebra.org/ perhaps.
https://nalgebra.org/rustdoc/nalgebra/base/struct.Matrix.html#method.transpose

Does ndarray::ArrayBase::t suit your needs?

hey thx, for the replies. Both solutions didn't worked for me. But they brought me on path
I think i found what I need by using swap_axes:

let mut a = arr3(&[
[[1, 2, 3], [4, 5, 6]],
[[7, 8, 9], [10, 11, 12]],
[[13, 14, 15], [16, 17, 18]],
[[19, 20, 21], [22, 23, 24]],
]);
a.swap_axes(0, 2);
a.swap_axes(1, 2);

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.