Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

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 8, Windows 7, Windows Server 2012, Windows Server 2008 R2

F# Core Library Versions

Supported in: 2.0, 4.0, Portable

© 2015 Microsoft