Logo

Programming-Idioms

  • JS
  • Dart
  • Fortran

Idiom #26 Create a 2-dimensional array

Declare and initialize a matrix x having m rows and n columns, containing real numbers.

  real, dimension(m,n) :: x
const x = new Array(m).fill(new Array(n).fill(Math.random()));
var x = [];
for (var i = 0; i < m; i++) {
  x[i] = [];
}
var x = new List.generate(m, (_) => new List(n));
var x = new List.generate(m, (_) => new List.filled(n, 0));
X : array (1 .. M, 1 .. N) of Float := (others => (others => 1.0));

New implementation...