Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Obj-c

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
NSArray *x=@[
  @[
    @[@0.1, @0.2, ... ], // p column values
    ... // n sub-rows
  ],
  ... // m rows
];

Object arrays are one-dimensional, but can contain nested arrays (accessible later, if needed, through x[i][j][k] all right). With plain-C types it would be precisely same as in plain C. Compare also idiom #26
X : array (1 .. M, 1 .. N, 1 .. P) of Float := (others => (others => (others => 1.0)));

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