How to slice a 3-dimensional array

2026-10-13来源 Rust Users ForumEnglish

I have a three-dimensional array like this:

const XDIM = 60; const YDIM = 60; const ZDIM = 2; let mut world = [[[0.0; ZDIM] ; YDIM]; XDIM]; 

How would I extract all the X and Y contents for a single Z-value, giving me something like a variable of the type

[[f64; YDIM] ; XDIM] 

Would it be easier/possible to reorganize the array so the z-axis is on the outside and I can slice it like

let mut world = [[[0.0; YDIM] ; XDIM]; ZDIM]; let z = 0; let slice = world[z]; 

Thanks! :3

1 post - 1 participant

Read full topic

原文:https://www.a8q9.cn/en/article/how-to-slice-a-3-dimensional-array-5b4768.html

相关文章