Property Item
property Item: int64 -> Tensor<'T>
Accesses a slice (part) of the tensor.
Declaration
property Item: int64 -> Tensor<'T> with get, set
Parameters
Type | Name | Description |
---|---|---|
int64 | i0 | The range of the tensor to select. |
Property Value
Type | Description |
---|---|
Tensor<'T> | A view of the selected part of the tensor. |
Remarks
Indexing is zero-based.
This indexing options allows to select a part (called slice) of the tensor.
The get operation returns a view of the specified part of the tensor. Modifications done to that view will affect the original tensor. Also, modifying the orignal tensor will affect the view.
The slicing specifications follows standard F# practice.
Specifying an integer for the index of a dimension, selects that index for the dimension.
Specifying *
for a dimension, selects all indices of the dimension.
Specifying f..l
for a dimension, select all indices from f
to (including) l
for the dimension.
For clarity the documentation does not list all overloads of the Item property and GetSlice, SetSlice methods. However, this slicing method can be used for up to 5 dimensions, as shown in the example. For programmatically generated ranges or for more than 5 dimensions, the range specification variant property Item: Rng list -> Tensor<'T> is available.
Examples
let a = HostTensor.ofList [[1.0; 2.0; 3.0]
[4.0; 5.0; 6.0]]
// get view
let b = a.[0L, 1L] // b = 2.0
let c = a.[0L, *] // b = [1.0; 2.0; 3.0]
let d = a.[1L, 0L..1L] // b = [4.0; 5.0]
let e = a.[1L..1L, 0L..1L] // b = [[4.0; 5.0]]
// set view
a.[0L, *] <- HostTensor.ofList [7.0; 8.0; 9.0] // a = [[7.0; 8.0; 9.0]
// [4.0; 5.0; 6.0]]
// modifiying view affects original tensor
d.[[1L]] <- 0.0 // a = [[7.0; 8.0; 9.0]
// [4.0; 0.0; 6.0]]
Exceptions
Type | Condition |
---|---|
System.IndexOutOfRangeException | Raised when the specified range is out of range. |
See Also
property Item: Rng list -> Tensor<'T>
Accesses a slice (part) of the tensor.
Declaration
property Item: Rng list -> Tensor<'T> with get, set
Parameters
Type | Name | Description |
---|---|---|
Rng list | rng | The range of the tensor to select. |
Property Value
Type | Description |
---|---|
Tensor<'T> | A view of the selected part of the tensor. |
Remarks
This range specification variant is intended for programmatically generated ranges. For most use cases the variant property Item: int64 -> Tensor<'T> allows vastly simpler range specifications and is the recommended method.
Indexing is zero-based.
This indexing options allows to select a part (called slice) of the tensor.
The get operation returns a view of the specified part of the tensor. Modifications done to that view will affect the original tensor. Also, modifying the orignal tensor will affect the view.
See Rng (union) for available range specifications.
Examples
let a = HostTensor.ofList [[1.0; 2.0; 3.0]
[4.0; 5.0; 6.0]]
// get view
let b = a.[[Rng.Elem 0L; Rng.Elem 1L]] // b = 2.0
let c = a.[[Rng.Elem 0L; Rng.All]] // b = [1.0; 2.0; 3.0]
let d = a.[[Rng.Elem 1L; Rng.Rng (Some 0L, Some 1L)]] // b = [4.0; 5.0]
let e = a.[[Rng.Rng (Some 1L, Some 1L); Rng (Some 0L, Some 1L)]] // b = [[4.0; 5.0]]
// set view
a.[[Rng.Elem 0L; Rng.All]] <- HostTensor.ofList [7.0; 8.0; 9.0] // a = [[7.0; 8.0; 9.0]
// [4.0; 5.0; 6.0]]
// modifiying view affects original tensor
d.[[1L]] <- 0.0 // a = [[7.0; 8.0; 9.0]
// [4.0; 0.0; 6.0]]
Exceptions
Type | Condition |
---|---|
System.IndexOutOfRangeException | Raised when the specified range is out of range. |
See Also
property Item: int64 list -> 'T
Accesses a single element within the tensor.
Declaration
property Item: int64 list -> 'T with get, set
Parameters
Type | Name | Description |
---|---|---|
int64 list | idx | A list consisting of the indicies of the element to access. The list must have one entry per dimension of this tensor. |
Property Value
Type | Description |
---|---|
'T | The value of the selected element. |
Remarks
Indexing is zero-based.
Use property Item: int64 [] -> 'T for faster element access.
Examples
let a = HostTensor.ofList [[1.0; 2.0]
[3.0; 4.0]]
let b = a.[[1L; 1L]] // b = 4.0
a.[[1L; 0L]] <- 6.0 // a = [[1.0; 2.0]
// [6.0; 4.0]]
Exceptions
Type | Condition |
---|---|
System.IndexOutOfRangeException | Raised when the specified indicies are out of range. |
See Also
property Item: int64 [] -> 'T
Accesses a single element within the tensor.
Declaration
property Item: int64 [] -> 'T with get, set
Parameters
Type | Name | Description |
---|---|---|
int64 [] | idx | An array consisting of the indicies of the element to access. The arry must have one entry per dimension of this tensor. |
Property Value
Type | Description |
---|---|
'T | The value of the selected element. |
Remarks
Indexing is zero-based.
Examples
let a = HostTensor.ofList [[1.0; 2.0]
[3.0; 4.0]]
let b = a.[[|1L; 1L|]] // b = 4.0
a.[[|1L; 0L|]] <- 6.0 // a = [[1.0; 2.0]
// [6.0; 4.0]]
Exceptions
Type | Condition |
---|---|
System.IndexOutOfRangeException | Raised when the specified indicies are out of range. |