Table of contents
Collapse the table of content
Expand the table of content

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

Den Delimarsky|Last Updated: 10/30/2017
2 Contributors

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


length1 Type: int

The length of the first dimension of the array.

length2 Type: int

The length of the second dimension of the array.

initializer Type: int->int-> 'T

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

Return Value

Returns 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

Version Information

F# Core Library Versions

Supported in: 2.0, 4.0, Portable

See Also

Collections.Array2D Module (F#)

Microsoft.FSharp.Collections Namespace (F#)

© 2020 Microsoft