FSharp.Core


Array3D Module

Contains operations for working with rank 3 arrays.

See also F# Language Guide - Arrays.

Functions and values

Function or value Description

Array3D.create length1 length2 length3 initial

Full Usage: Array3D.create length1 length2 length3 initial

Parameters:
    length1 : int - The length of the first dimension.
    length2 : int - The length of the second dimension.
    length3 : int - The length of the third dimension.
    initial : 'T - The value of the array elements.

Returns: 'T[,,] The created array.

Creates an array whose elements are all initially the given value.

length1 : int

The length of the first dimension.

length2 : int

The length of the second dimension.

length3 : int

The length of the third dimension.

initial : 'T

The value of the array elements.

Returns: 'T[,,]

The created array.

Example


 Array3D.create 2 2 3 1
Evaluates to a 2x3 array with contents [[[1; 1; 1]; [1; 1; 1]]; [[1; 1; 1]; [1; 1; 1]]]

Array3D.get array index1 index2 index3

Full Usage: Array3D.get array index1 index2 index3

Parameters:
    array : 'T[,,] - The input array.
    index1 : int - The index along the first dimension.
    index2 : int - The index along the second dimension.
    index3 : int - The index along the third dimension.

Returns: 'T The value at the given index.

Fetches an element from a 3D array. You can also use the syntax 'array.[index1,index2,index3]'

Indexer syntax is generally preferred, e.g.


 let array = Array3D.init 2 3 3 (fun i j k -> 100*i + 10*j + k)

 array[0,2,1]
Evaluates to 11.

array : 'T[,,]

The input array.

index1 : int

The index along the first dimension.

index2 : int

The index along the second dimension.

index3 : int

The index along the third dimension.

Returns: 'T

The value at the given index.

Example


 let array = Array3D.init 2 3 3 (fun i j k -> 100*i + 10*j + k)

 Array3D.get array 0 2 1
Evaluates to 21.

Array3D.init length1 length2 length3 initializer

Full Usage: Array3D.init length1 length2 length3 initializer

Parameters:
    length1 : int - The length of the first dimension.
    length2 : int - The length of the second dimension.
    length3 : int - The length of the third dimension.
    initializer : int -> int -> int -> 'T - The function to create an initial value at each index into the array.

Returns: 'T[,,] The created array.

Creates an array given the dimensions and a generator function to compute the elements.

length1 : int

The length of the first dimension.

length2 : int

The length of the second dimension.

length3 : int

The length of the third dimension.

initializer : int -> int -> int -> 'T

The function to create an initial value at each index into the array.

Returns: 'T[,,]

The created array.

Example


 Array3D.init 2 2 3 (fun i j k -> 100*i + 10*j + k)
Evaluates to a 2x2x3 array with contents [[[0; 1; 2]; [10; 11; 12]]; [[100; 101; 102]; [110; 111; 112]]]

Array3D.iter action array

Full Usage: Array3D.iter action array

Parameters:
    action : 'T -> unit - The function to apply to each element of the array.
    array : 'T[,,] - The input array.

Applies the given function to each element of the array.

action : 'T -> unit

The function to apply to each element of the array.

array : 'T[,,]

The input array.

Example


 let inputs = Array3D.init 2 2 3 (fun i j k -> 100*i + 10*j + k)

 inputs |> Array3D.iter (fun v -> printfn $"value = {v}")
Evaluates to unit and prints

 value = 0
 value = 1
 value = 2
 value = 10
 value = 11
 value = 12
 value = 100
 value = 101
 value = 102
 value = 110
 value = 111
 value = 112
in the console.

Array3D.iteri action array

Full Usage: Array3D.iteri action array

Parameters:
    action : int -> int -> int -> 'T -> unit - The function to apply to each element of the array.
    array : 'T[,,] - The input array.

Applies the given function to each element of the array. The integer indices passed to the function indicates the index of element.

action : int -> int -> int -> 'T -> unit

The function to apply to each element of the array.

array : 'T[,,]

The input array.

Example


 let inputs = Array3D.init 2 2 3 (fun i j k -> 100*i + 10*j + k)

 inputs |> Array3D.iteri (fun i j k v -> printfn $"value at ({i},{j},{k}) = {v}")
Evaluates to unit and prints

 value at (0,0,0) = 0
 value at (0,0,1) = 1
 value at (0,0,2) = 2
 value at (0,1,0) = 10
 value at (0,1,1) = 11
 value at (0,1,2) = 12
 value at (1,0,0) = 100
 value at (1,0,1) = 101
 value at (1,0,2) = 102
 value at (1,1,0) = 110
 value at (1,1,1) = 111
 value at (1,1,2) = 112
in the console.

Array3D.length1 array

Full Usage: Array3D.length1 array

Parameters:
    array : '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

array : 'T[,,]

The input array.

Returns: int

The length of the array in the first dimension.

Example


 let array = Array3D.init 2 3 4 (fun i j k -> 100*i + 10*j + k)

 array |> Array3D.length1
Evaluates to 2.

Array3D.length2 array

Full Usage: Array3D.length2 array

Parameters:
    array : '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.

array : 'T[,,]

The input array.

Returns: int

The length of the array in the second dimension.

Example


 let array = Array3D.init 2 3 4 (fun i j k -> 100*i + 10*j + k)

 array |> Array3D.length2
Evaluates to 3.

Array3D.length3 array

Full Usage: Array3D.length3 array

Parameters:
    array : 'T[,,] - The input array.

Returns: int The length of the array in the third dimension.

Returns the length of an array in the third dimension.

array : 'T[,,]

The input array.

Returns: int

The length of the array in the third dimension.

Example


 let array = Array3D.init 2 3 4 (fun i j k -> 100*i + 10*j + k)

 array |> Array3D.length3
Evaluates to 4.

Array3D.map mapping array

Full Usage: Array3D.map mapping array

Parameters:
    mapping : 'T -> 'U - The function to transform each element of the array.
    array : 'T[,,] - The input array.

Returns: 'U[,,] The array created from the transformed elements.

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.

mapping : 'T -> 'U

The function to transform each element of the array.

array : 'T[,,]

The input array.

Returns: 'U[,,]

The array created from the transformed elements.

Example


 let inputs = Array3D.init 2 3 3 (fun i j k -> 100*i + 10*j + k)

 inputs |> Array3D.map (fun v -> 2 * v)
Evaluates to a 2x3x3 array with contents [[[0; 2; 4]; [20; 22; 24]]; [[200; 202; 204]; [220; 222; 224]]]

Array3D.mapi mapping array

Full Usage: Array3D.mapi mapping array

Parameters:
    mapping : int -> int -> int -> 'T -> 'U - The function to transform the elements at each index in the array.
    array : 'T[,,] - The input array.

Returns: 'U[,,] The array created from the transformed elements.

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.

mapping : int -> int -> int -> 'T -> 'U

The function to transform the elements at each index in the array.

array : 'T[,,]

The input array.

Returns: 'U[,,]

The array created from the transformed elements.

Example


 let inputs = Array3D.zeroCreate 2 3 3

 inputs |> Array3D.mapi (fun i j k v -> 100*i + 10*j + k)
Evaluates to a 2x3x3 array with contents [[[0; 2; 4]; [20; 22; 24]]; [[200; 202; 204]; [220; 222; 224]]]

Array3D.set array index1 index2 index3 value

Full Usage: Array3D.set array index1 index2 index3 value

Parameters:
    array : 'T[,,] - The input array.
    index1 : int - The index along the first dimension.
    index2 : int - The index along the second dimension.
    index3 : int - The index along the third dimension.
    value : 'T - The value to set at the given index.

Sets the value of an element in an array. You can also use the syntax 'array.[index1,index2,index3] <- value'.

Indexer syntax is generally preferred, e.g.


 let array = Array3D.zeroCreate 2 3 3

 array[0,2,1] < 4.0
Evaluates to 11.

array : 'T[,,]

The input array.

index1 : int

The index along the first dimension.

index2 : int

The index along the second dimension.

index3 : int

The index along the third dimension.

value : 'T

The value to set at the given index.

Example


 let array = Array3D.zeroCreate 2 3 3

 Array3D.set array 0 2 1 4.0
After evaluation array is a 2x3x3 array with contents [[[0.0; 0.0; 0.0]; [0.0; 4.0; 0.0]]; [[0.0; 0.0; 0.0]; [0.0; 0.0; 0.0]]]

Array3D.zeroCreate length1 length2 length3

Full Usage: Array3D.zeroCreate length1 length2 length3

Parameters:
    length1 : int - The length of the first dimension.
    length2 : int - The length of the second dimension.
    length3 : int - The length of the third dimension.

Returns: 'T[,,] The created array.

Creates an array where the entries are initially the "default" value.

length1 : int

The length of the first dimension.

length2 : int

The length of the second dimension.

length3 : int

The length of the third dimension.

Returns: 'T[,,]

The created array.

Example


 let array : float[,,] = Array3D.zeroCreate 2 3 3
After evaluation array is a 2x3x3 array with contents all zero.