rust 堆上二维数组

阅读量: searchstar 2021-09-15 16:56:00
Categories: Tags:

用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");
    }
}