0

How can I initialize a 3D matrix in Rust given the number number of component in x, y, z and a given nuber for intialization (let's say 1.0). At the moment I use no librares:

    let nx: usize = 100;                              // y-resolution
    let nl: usize = 4000;                             // z-resolution
    let f = vec![vec![vec![1.0; nl]; ny]; nx]; ``` 

But I think there should be a more efficient way in the "nalgebra" library, but everything  seems really cumbersome. Thanks in advance.
Mattia Samiolo
  • 365
  • 2
  • 8
  • see [nalgebra](https://docs.rs/nalgebra/latest/nalgebra/base/struct.Matrix.html#examples-1) examples – palik Jul 17 '22 at 09:44

1 Answers1

1

I think what you're looking for is not nalgebra, but ndarray.

The former is a crate for linear algebra, which focuses on vectors and 2D matrices, and the latter handles multi-dimensional data.

The crate's docs have examples on how to achieve what you want:

use ndarray::Array3;
let f = Array3::<f64>::ones((nx, ny, nl));
ransh
  • 41
  • 1
  • 6