Array2D.init<'T> Function (F#)

Creates an array given the dimensions and a generator function to compute the elements.

Namespace/Module Path: Microsoft.FSharp.Collections.Array2D

Assembly: FSharp.Core (in FSharp.Core.dll)

// Signature:
Array2D.init : int -> int -> (int -> int -> 'T) -> 'T [,]

// Usage:
Array2D.init length1 length2 initializer


Type: int

The length of the first dimension of the array.


Type: int

The length of the second dimension of the array.


Type: int -> int -> 'T

A function to produce elements of the array given the two indices.




Thrown when either of the lengths is negative.

The generated array.

This function is named Initialize in compiled assemblies. If you are accessing the function from a language other than F#, or through reflection, use this name.

The following code demonstrates the use of Array2D.init to create a two-dimensional array.

let arrayOfArrays = [| [| 1.0; 0.0 |]; [|0.0; 1.0 |] |]
let twoDimensionalArray = Array2D.init 2 2 (fun i j -> arrayOfArrays.[i].[j]) 

Windows 7, Windows Vista SP2, Windows XP SP3, Windows XP x64 SP2, Windows Server 2008 R2, Windows Server 2008 SP2, Windows Server 2003 SP2

F# Runtime

Supported in: 2.0, 4.0


Supported in: 3

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

© 2015 Microsoft