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

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.

Exception

Condition

ArgumentException

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

Show:
© 2014 Microsoft