rust 堆上二维数组

用ndarray:

https://docs.rs/ndarray/0.15.3/ndarray/
Rust 多维数组 ndarray

例子:

use ndarray::Array2;

fn main() {
    let mut a = Array2::<usize>::zeros((2, 3));
    println!("{:?}", a.dim());
    for i in 0..2 {
        for j in 0..3 {
            a[[i, j]] = i + j;
        }
    }
    for i in 0..a.dim().0 {
        for j in 0..a.dim().1 {
            print!("{}", a[[i, j]]);
        }
        print!("\n");
    }
}
posted @ 2024-09-28 14:16  寻找繁星  阅读(9)  评论(0编辑  收藏  举报