Array2D Module
Contains operations for working with 2-dimensional arrays.
See also F# Language Guide - Arrays.
F# and CLI multi-dimensional arrays are typically zero-based.
However, CLI multi-dimensional arrays used in conjunction with external
libraries (e.g. libraries associated with Visual Basic) be
non-zero based, using a potentially different base for each dimension.
The operations in this module will accept such arrays, and
the basing on an input array will be propagated to a matching output
array on the Array2D.map
and Array2D.mapi
operations.
Non-zero-based arrays can also be created using Array2D.zeroCreateBased
,
Array2D.createBased
and Array2D.initBased
.
Functions and values
Function or value |
Description
|
||
Full Usage:
Array2D.base1 array
Parameters:
'T[,]
-
The input array.
Returns: int
The base-index of the first dimension of the array.
|
Fetches the base-index for the first dimension of the array.
ExampleCreate a 10x10 1-based array:
namespace System
Multiple items
val array: int array2d -------------------- type 'T array = 'T array type Array =
interface ICollection
interface IEnumerable
interface IList
interface IStructuralComparable
interface IStructuralEquatable
interface ICloneable
member Clone: unit -> obj
member CopyTo: array: Array * index: int -> unit + 1 overload
member GetEnumerator: unit -> IEnumerator
member GetLength: dimension: int -> int
...
<summary>Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the base class for all arrays in the common language runtime.</summary> Array.CreateInstance(elementType: Type, [<ParamArray>] lengths: int64 array) : Array
Array.CreateInstance(elementType: Type, [<ParamArray>] lengths: int array) : Array Array.CreateInstance(elementType: Type, length: int) : Array Array.CreateInstance(elementType: Type, lengths: int array, lowerBounds: int array) : Array Array.CreateInstance(elementType: Type, length1: int, length2: int) : Array Array.CreateInstance(elementType: Type, length1: int, length2: int, length3: int) : Array val typeof<'T> : Type
Multiple items
val int: value: 'T -> int (requires member op_Explicit) -------------------- type int = int32 -------------------- type int<'Measure> = int module Array2D
from Microsoft.FSharp.Collections
val base1: array: 'T array2d -> int
Evaluates to 1 .
|
||
Full Usage:
Array2D.base2 array
Parameters:
'T[,]
-
The input array.
Returns: int
The base-index of the second dimension of the array.
|
Fetches the base-index for the second dimension of the array.
ExampleCreate a 10x10 1-based array:
namespace System
Multiple items
val array: int array2d -------------------- type 'T array = 'T array type Array =
interface ICollection
interface IEnumerable
interface IList
interface IStructuralComparable
interface IStructuralEquatable
interface ICloneable
member Clone: unit -> obj
member CopyTo: array: Array * index: int -> unit + 1 overload
member GetEnumerator: unit -> IEnumerator
member GetLength: dimension: int -> int
...
<summary>Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the base class for all arrays in the common language runtime.</summary> Array.CreateInstance(elementType: Type, [<ParamArray>] lengths: int64 array) : Array
Array.CreateInstance(elementType: Type, [<ParamArray>] lengths: int array) : Array Array.CreateInstance(elementType: Type, length: int) : Array Array.CreateInstance(elementType: Type, lengths: int array, lowerBounds: int array) : Array Array.CreateInstance(elementType: Type, length1: int, length2: int) : Array Array.CreateInstance(elementType: Type, length1: int, length2: int, length3: int) : Array val typeof<'T> : Type
Multiple items
val int: value: 'T -> int (requires member op_Explicit) -------------------- type int = int32 -------------------- type int<'Measure> = int module Array2D
from Microsoft.FSharp.Collections
val base2: array: 'T array2d -> int
Evaluates to 1 .
|
||
Full Usage:
Array2D.blit source sourceIndex1 sourceIndex2 target targetIndex1 targetIndex2 length1 length2
Parameters:
'T[,]
-
The source array.
sourceIndex1 : int
-
The first-dimension index to begin copying from in the source array.
sourceIndex2 : int
-
The second-dimension index to begin copying from in the source array.
target : 'T[,]
-
The target array.
targetIndex1 : int
-
The first-dimension index to begin copying into in the target array.
targetIndex2 : int
-
The second-dimension index to begin copying into in the target array.
length1 : int
-
The number of elements to copy across the first dimension of the arrays.
length2 : int
-
The number of elements to copy across the second dimension of the arrays.
|
Reads a range of elements from the first array and write them into the second. Slicing syntax is generally preferred, e.g.
val source: int array2d
val array2D: rows: #('T seq) seq -> 'T array2d
val target: int array2d
Example
val source: int array2d
val array2D: rows: #('T seq) seq -> 'T array2d
val target: int array2d
module Array2D
from Microsoft.FSharp.Collections
val blit: source: 'T array2d -> sourceIndex1: int -> sourceIndex2: int -> target: 'T array2d -> targetIndex1: int -> targetIndex2: int -> length1: int -> length2: int -> unit
After evaluation target contains [ [ 2; 3; 4 ]; [ 12; 13; 14 ] ] .
|
||
Full Usage:
Array2D.copy array
Parameters:
'T[,]
-
The input array.
Returns: 'T[,]
A copy of the input array.
|
Builds a new array whose elements are the same as the input array. For non-zero-based arrays the basing on an input array will be propagated to the output array.
Example
namespace System
Multiple items
val array: int array2d -------------------- type 'T array = 'T array module Array2D
from Microsoft.FSharp.Collections
val zeroCreate: length1: int -> length2: int -> 'T array2d
Multiple items
val int: value: 'T -> int (requires member op_Explicit) -------------------- type int = int32 -------------------- type int<'Measure> = int val copy: array: 'T array2d -> 'T array2d
Evaluates to a new copy of the 10x10 array.
|
||
|
Creates an array whose elements are all initially the given value.
Example
module Array2D
from Microsoft.FSharp.Collections
val create: length1: int -> length2: int -> value: 'T -> 'T array2d
Evaluates to a 2x3 array with contents [[1; 1; 1]; [1; 1; 1]]
|
||
Full Usage:
Array2D.createBased base1 base2 length1 length2 initial
Parameters:
int
-
The base for the first dimension of the array.
base2 : int
-
The base for the second dimension of the array.
length1 : int
-
The length of the first dimension of the array.
length2 : int
-
The length of the second dimension of the array.
initial : 'T
-
The value to populate the new array.
Returns: 'T[,]
The created array.
|
Creates a based array whose elements are all initially the given value.
Example
module Array2D
from Microsoft.FSharp.Collections
val createBased: base1: int -> base2: int -> length1: int -> length2: int -> initial: 'T -> 'T array2d
Evaluates to a 2x3 1-based array with contents [[1; 1; 1]; [1; 1; 1]]
|
||
|
Fetches an element from a 2D array. You can also use the syntax Indexer syntax is generally preferred, e.g.
Multiple items
val array: float array2d -------------------- type 'T array = 'T array val array2D: rows: #('T seq) seq -> 'T array2d
Evaluates to 2.0 .
Example
Multiple items
val array: float array2d -------------------- type 'T array = 'T array val array2D: rows: #('T seq) seq -> 'T array2d
module Array2D
from Microsoft.FSharp.Collections
val get: array: 'T array2d -> index1: int -> index2: int -> 'T
Evaluates to 2.0 .
|
||
Full Usage:
Array2D.init length1 length2 initializer
Parameters:
int
-
The length of the first dimension of the array.
length2 : int
-
The length of the second dimension of the array.
initializer : int -> int -> 'T
-
A function to produce elements of the array given the two indices.
Returns: 'T[,]
The generated array.
|
Creates an array given the dimensions and a generator function to compute the elements.
Example
module Array2D
from Microsoft.FSharp.Collections
val init: length1: int -> length2: int -> initializer: (int -> int -> 'T) -> 'T array2d
val i: int
val j: int
Evaluates to a 2x3 array with contents [[0; 1; 2]; [1; 2; 3]]
|
||
Full Usage:
Array2D.initBased base1 base2 length1 length2 initializer
Parameters:
int
-
The base for the first dimension of the array.
base2 : int
-
The base for the second dimension of the array.
length1 : int
-
The length of the first dimension of the array.
length2 : int
-
The length of the second dimension of the array.
initializer : int -> int -> 'T
-
A function to produce elements of the array given the two indices.
Returns: 'T[,]
The created array.
|
Creates a based array given the dimensions and a generator function to compute the elements.
Example
module Array2D
from Microsoft.FSharp.Collections
val initBased: base1: int -> base2: int -> length1: int -> length2: int -> initializer: (int -> int -> 'T) -> 'T array2d
val i: int
val j: int
Evaluates to a 2x3 1-based array with contents [[2; 3; 4]; [3; 4; 5]]
|
||
Full Usage:
Array2D.iter action array
Parameters:
'T -> unit
-
A function to apply to each element of the array.
array : 'T[,]
-
The input array.
|
Applies the given function to each element of the array.
Example
val inputs: int array2d
val array2D: rows: #('T seq) seq -> 'T array2d
module Array2D
from Microsoft.FSharp.Collections
val iter: action: ('T -> unit) -> array: 'T array2d -> unit
val v: int
val printfn: format: Printf.TextWriterFormat<'T> -> 'T
Evaluates to unit and prints
in the console.
|
||
|
Applies the given function to each element of the array. The integer indices passed to the function indicates the index of element.
Example
val inputs: int array2d
val array2D: rows: #('T seq) seq -> 'T array2d
module Array2D
from Microsoft.FSharp.Collections
val iteri: action: (int -> int -> 'T -> unit) -> array: 'T array2d -> unit
val i: int
val j: int
val v: int
val printfn: format: Printf.TextWriterFormat<'T> -> 'T
Evaluates to unit and prints
in the console.
|
||
Full Usage:
Array2D.length1 array
Parameters:
'T[,]
-
The input array.
Returns: int
The length of the array in the first dimension.
|
Returns the length of an array in the first dimension.
Example
Multiple items
val array: int array2d -------------------- type 'T array = 'T array val array2D: rows: #('T seq) seq -> 'T array2d
module Array2D
from Microsoft.FSharp.Collections
val length1: array: 'T array2d -> int
Evaluates to 2 .
|
||
Full Usage:
Array2D.length2 array
Parameters:
'T[,]
-
The input array.
Returns: int
The length of the array in the second dimension.
|
Returns the length of an array in the second dimension.
Example
Multiple items
val array: int array2d -------------------- type 'T array = 'T array val array2D: rows: #('T seq) seq -> 'T array2d
module Array2D
from Microsoft.FSharp.Collections
val length2: array: 'T array2d -> int
Evaluates to 3 .
|
||
Full Usage:
Array2D.map mapping array
Parameters:
'T -> 'U
-
A function that is applied to transform each item of the input array.
array : 'T[,]
-
The input array.
Returns: 'U[,]
An array whose elements have been transformed by the given mapping.
|
Builds a new array whose elements are the results of applying the given function to each of the elements of the array. For non-zero-based arrays the basing on an input array will be propagated to the output array.
Example
val inputs: int array2d
val array2D: rows: #('T seq) seq -> 'T array2d
module Array2D
from Microsoft.FSharp.Collections
val map: mapping: ('T -> 'U) -> array: 'T array2d -> 'U array2d
val v: int
Evaluates to a 2x2 array with contents [[6; 8;]; [26; 28]]
|
||
Full Usage:
Array2D.mapi mapping array
Parameters:
int -> int -> 'T -> 'U
-
A function that is applied to transform each element of the array. The two integers
provide the index of the element.
array : 'T[,]
-
The input array.
Returns: 'U[,]
An array whose elements have been transformed by the given mapping.
|
Builds a new array whose elements are the results of applying the given function to each of the elements of the array. The integer indices passed to the function indicates the element being transformed. For non-zero-based arrays the basing on an input array will be propagated to the output array.
Example
val inputs: int array2d
val array2D: rows: #('T seq) seq -> 'T array2d
module Array2D
from Microsoft.FSharp.Collections
val mapi: mapping: (int -> int -> 'T -> 'U) -> array: 'T array2d -> 'U array2d
val i: int
val j: int
val v: int
Evaluates to a 2x2 array with contents [[3; 5;]; [14; 16]]
|
||
Full Usage:
Array2D.rebase array
Parameters:
'T[,]
-
The input array.
Returns: 'T[,]
The zero-based output array.
|
Builds a new array whose elements are the same as the input array but where a non-zero-based input array generates a corresponding zero-based output array.
Example
val inputs: int array2d
module Array2D
from Microsoft.FSharp.Collections
val createBased: base1: int -> base2: int -> length1: int -> length2: int -> initial: 'T -> 'T array2d
val rebase: array: 'T array2d -> 'T array2d
Evaluates to a 2x2 zero-based array with contents [[1; 1]; [1; 1]]
|
||
|
Sets the value of an element in an array. You can also use the syntax Indexer syntax is generally preferred, e.g.
Multiple items
val array: float array2d -------------------- type 'T array = 'T array module Array2D
from Microsoft.FSharp.Collections
val zeroCreate: length1: int -> length2: int -> 'T array2d
Example
Multiple items
val array: float array2d -------------------- type 'T array = 'T array module Array2D
from Microsoft.FSharp.Collections
val zeroCreate: length1: int -> length2: int -> 'T array2d
val set: array: 'T array2d -> index1: int -> index2: int -> value: 'T -> unit
After evaluation array is a 2x2 array with contents [[0.0; 4.0]; [0.0; 0.0]]
|
||
|
Creates an array where the entries are initially Unchecked.defaultof<'T>.
Example
module Array2D
from Microsoft.FSharp.Collections
val zeroCreate: length1: int -> length2: int -> 'T array2d
Evaluates to a 2x3 array with contents [[0; 0; 0]; [0; 0; 0]]
|
||
Full Usage:
Array2D.zeroCreateBased base1 base2 length1 length2
Parameters:
int
-
The base for the first dimension of the array.
base2 : int
-
The base for the second dimension of the array.
length1 : int
-
The length of the first dimension of the array.
length2 : int
-
The length of the second dimension of the array.
Returns: 'T[,]
The created array.
|
Creates a based array where the entries are initially Unchecked.defaultof<'T>.
Example
module Array2D
from Microsoft.FSharp.Collections
val zeroCreateBased: base1: int -> base2: int -> length1: int -> length2: int -> 'T array2d
Evaluates to a 2x3 1-based array with contents [[0; 0; 0]; [0; 0; 0]]
|