Logo

Programming-Idioms

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

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
var x = new List.generate(m, (_) => 
                new List.generate(n, (_) => 
                    new List.filled(p, 0.0), 
                    growable: false), 
                growable: false);

Dart does not have multidimensional arrays as a primitive, this is a list of lists of lists of doubles, all fixed-length lists.
X : array (1 .. M, 1 .. N, 1 .. P) of Float := (others => (others => (others => 1.0)));

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