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
Parameters
length1
Type: intThe length of the first dimension of the array.
length2
Type: intThe length of the second dimension of the array.
initializer
Type: int -> int -> 'TA function to produce elements of the array given the two indices.
Exceptions
Exception |
Condition |
---|---|
Thrown when either of the lengths is negative. |
Return Value
The generated array.
Remarks
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.
Example
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])
Platforms
Windows 8, Windows 7, Windows Server 2012, Windows Server 2008 R2
Version Information
F# Core Library Versions
Supported in: 2.0, 4.0, Portable