Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Rust

Idiom #27 Create a 3-dimensional array

Declare and initialize a 3D array x, having dimensions boundaries m, n, p, and containing real numbers.

A 3D matrix with iteration variables i for rows, j for columns, k for depth
let x = [[[0.0f64; P]; N]; M];

Stack-allocated array.

M, N, P are constants.
let x = vec![vec![vec![0.0f64; p]; n]; m];

m, n, p don't have to be constants
X : array (1 .. M, 1 .. N, 1 .. P) of Float := (others => (others => (others => 1.0)));

New implementation...
< >
programming-idioms.org