Header menu logo 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
module Array3D from Microsoft.FSharp.Collections
val create: length1: int -> length2: int -> length3: int -> initial: 'T -> 'T array3d
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]
Multiple items
val array: int array3d

--------------------
type 'T array = 'T array
module Array3D from Microsoft.FSharp.Collections
val init: length1: int -> length2: int -> length3: int -> initializer: (int -> int -> int -> 'T) -> 'T array3d
val i: int
val j: int
val k: int
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
Multiple items
val array: int array3d

--------------------
type 'T array = 'T array
module Array3D from Microsoft.FSharp.Collections
val init: length1: int -> length2: int -> length3: int -> initializer: (int -> int -> int -> 'T) -> 'T array3d
val i: int
val j: int
val k: int
val get: array: 'T array3d -> index1: int -> index2: int -> index3: int -> 'T
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)
module Array3D from Microsoft.FSharp.Collections
val init: length1: int -> length2: int -> length3: int -> initializer: (int -> int -> int -> 'T) -> 'T array3d
val i: int
val j: int
val k: int
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}")
val inputs: int array3d
module Array3D from Microsoft.FSharp.Collections
val init: length1: int -> length2: int -> length3: int -> initializer: (int -> int -> int -> 'T) -> 'T array3d
val i: int
val j: int
val k: int
val iter: action: ('T -> unit) -> array: 'T array3d -> unit
val v: int
val printfn: format: Printf.TextWriterFormat<'T> -> 'T
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}")
val inputs: int array3d
module Array3D from Microsoft.FSharp.Collections
val init: length1: int -> length2: int -> length3: int -> initializer: (int -> int -> int -> 'T) -> 'T array3d
val i: int
val j: int
val k: int
val iteri: action: (int -> int -> int -> 'T -> unit) -> array: 'T array3d -> unit
val v: int
val printfn: format: Printf.TextWriterFormat<'T> -> 'T
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
Multiple items
val array: int array3d

--------------------
type 'T array = 'T array
module Array3D from Microsoft.FSharp.Collections
val init: length1: int -> length2: int -> length3: int -> initializer: (int -> int -> int -> 'T) -> 'T array3d
val i: int
val j: int
val k: int
val length1: array: 'T array3d -> int
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
Multiple items
val array: int array3d

--------------------
type 'T array = 'T array
module Array3D from Microsoft.FSharp.Collections
val init: length1: int -> length2: int -> length3: int -> initializer: (int -> int -> int -> 'T) -> 'T array3d
val i: int
val j: int
val k: int
val length2: array: 'T array3d -> int
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
Multiple items
val array: int array3d

--------------------
type 'T array = 'T array
module Array3D from Microsoft.FSharp.Collections
val init: length1: int -> length2: int -> length3: int -> initializer: (int -> int -> int -> 'T) -> 'T array3d
val i: int
val j: int
val k: int
val length3: array: 'T array3d -> int
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)
val inputs: int array3d
module Array3D from Microsoft.FSharp.Collections
val init: length1: int -> length2: int -> length3: int -> initializer: (int -> int -> int -> 'T) -> 'T array3d
val i: int
val j: int
val k: int
val map: mapping: ('T -> 'U) -> array: 'T array3d -> 'U array3d
val v: int
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)
val inputs: obj array3d
module Array3D from Microsoft.FSharp.Collections
val zeroCreate: length1: int -> length2: int -> length3: int -> 'T array3d
val mapi: mapping: (int -> int -> int -> 'T -> 'U) -> array: 'T array3d -> 'U array3d
val i: int
val j: int
val k: int
val v: obj
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
Multiple items
val array: float array3d

--------------------
type 'T array = 'T array
module Array3D from Microsoft.FSharp.Collections
val zeroCreate: length1: int -> length2: int -> length3: int -> 'T array3d
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
Multiple items
val array: float array3d

--------------------
type 'T array = 'T array
module Array3D from Microsoft.FSharp.Collections
val zeroCreate: length1: int -> length2: int -> length3: int -> 'T array3d
val set: array: 'T array3d -> index1: int -> index2: int -> index3: int -> value: 'T -> unit
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
Multiple items
val array: float array3d

--------------------
type 'T array = 'T array
Multiple items
val float: value: 'T -> float (requires member op_Explicit)

--------------------
type float = System.Double

--------------------
type float<'Measure> = float
module Array3D from Microsoft.FSharp.Collections
val zeroCreate: length1: int -> length2: int -> length3: int -> 'T array3d
After evaluation array is a 2x3x3 array with contents all zero.

Type something to start searching.