0

Is it possible in Rust to create and initialise a 3D array (ndarray) with explicit indices? As I understand, by default Rust creates an array with zero-based indexing:

use ndarray::Array3;
...
const NX: usize = 100;
const NY: usize = 100;
const NZ: usize = 100;

let mut arr = Array3::<f32>::zeros((NX, NY, NZ));

This will create an array with indices running from 0 to 99. I would like to create an array with indices from 1 to 100. The below construct is not valid Rust code, but would be most welcome:

let mut arr = Array3::<f32>::zeros((1..100, 1..100, 1..100));

Is there a way to achieve this in Rust?

P.S. There are many stones being thrown at Fortran. But multidimensional arrays and indexing is what Fortran excels at!

mabalenk
  • 887
  • 1
  • 8
  • 17
  • 1
    Even if there would be a way to do that (which I don't think, not without your own crate), don't do that. Your code will look weird and confusing. And zero-based indexing has performance advantage, at least in language not planned for one-based indexing. – Chayim Friedman Jun 26 '23 at 16:58

0 Answers0