Tensor.Create From Function Method
Definition
Namespace: Numerics.NET.Tensors
Assembly: Numerics.NET.Tensors (in Numerics.NET.Tensors.dll) Version: 9.0.1
Assembly: Numerics.NET.Tensors (in Numerics.NET.Tensors.dll) Version: 9.0.1
Creates a tensor with values from a function.
Overload List
Create | Creates a new 1-dimensional tensor and initializes the elements using the specified function. |
Create | Creates a new 1-dimensional tensor and initializes the elements using the specified function."/> |
Create | Creates a new 2-dimensional tensor and initializes the elements using the specified function. |
Create | Creates a new 3-dimensional tensor and initializes the elements using the specified function. |
Create | Creates a new 4-dimensional tensor and initializes the elements using the specified function. |
CreateFromFunction<T>(Int32, Func<Int32, T>, ArrayMutability)
Creates a new 1-dimensional tensor and initializes the elements
using the specified function.
public static Tensor<T> CreateFromFunction<T>(
int length,
Func<int, T> function,
ArrayMutability mutability = ArrayMutability.MutableValues
)
Parameters
- length Int32
- The number of elements in the tensor.
- function Func<Int32, T>
- A function that computes the value of the tensor element for the specified index.
- mutability ArrayMutability (Optional)
- Optional. Specifies how the tensor's values may be changed. The default is mutable values.
Type Parameters
- T
- The type of the elements of the tensor.
Return Value
Tensor<T>A 1D tensor of length length initialized using function.
Exceptions
Argument | function is null. |
Argument | length is less than zero. |
CreateFromFunction<T>(TensorShape, Func<Int32, T>, ArrayMutability)
Creates a new 1-dimensional tensor and initializes the elements
using the specified function."/>
public static Tensor<T> CreateFromFunction<T>(
TensorShape shape,
Func<int, T> function,
ArrayMutability mutability = ArrayMutability.MutableValues
)
Parameters
- shape TensorShape
- The dimensions of the new tensor.
- function Func<Int32, T>
- A function that computes the value of the tensor element for the specified index.
- mutability ArrayMutability (Optional)
- Optional. Specifies how the tensor's values may be changed. The default is mutable values.
Type Parameters
- T
- The type of the elements of the tensor.
Return Value
Tensor<T>A 1D tensor with shape shape initialized using function.
Exceptions
Argument | function is null. |
Dimension | The rank of shape is not equal to one. |
Argument | One of the dimensions in shape is less than zero. |
CreateFromFunction<T>(TensorShape, Func<Int32, Int32, T>, TensorElementOrder, ArrayMutability)
Creates a new 2-dimensional tensor and initializes the elements
using the specified function.
public static Tensor<T> CreateFromFunction<T>(
TensorShape shape,
Func<int, int, T> function,
TensorElementOrder order = TensorElementOrder.CStyle,
ArrayMutability mutability = ArrayMutability.MutableValues
)
Parameters
- shape TensorShape
- The dimensions of the new tensor.
- function Func<Int32, Int32, T>
- A function that computes the value of the tensor element for the specified index.
- order TensorElementOrder (Optional)
- Optional. Specifies the element order of the result. By default, elements are stored in C-style (row-major) order.
- mutability ArrayMutability (Optional)
- Optional. Specifies how the tensor's values may be changed. The default is mutable values.
Type Parameters
- T
- The type of the elements of the tensor.
Return Value
Tensor<T>A 2D tensor with shape shape initialized using function.
Exceptions
Argument | function is null. |
Dimension | The rank of shape is not equal to 2. |
Argument | One of the dimensions in shape is less than zero. |
CreateFromFunction<T>(TensorShape, Func<Int32, Int32, Int32, T>, TensorElementOrder, ArrayMutability)
Creates a new 3-dimensional tensor and initializes the elements
using the specified function.
public static Tensor<T> CreateFromFunction<T>(
TensorShape shape,
Func<int, int, int, T> function,
TensorElementOrder order = TensorElementOrder.CStyle,
ArrayMutability mutability = ArrayMutability.MutableValues
)
Parameters
- shape TensorShape
- The dimensions of the new tensor.
- function Func<Int32, Int32, Int32, T>
- A function that computes the value of the tensor element for the specified index.
- order TensorElementOrder (Optional)
- Optional. Specifies the element order of the result. By default, elements are stored in C-style (row-major) order.
- mutability ArrayMutability (Optional)
- Optional. Specifies how the tensor's values may be changed. The default is mutable values.
Type Parameters
- T
- The type of the elements of the tensor.
Return Value
Tensor<T>A 3D tensor with shape shape initialized using function.
Exceptions
Argument | function is null. |
Dimension | The rank of shape is not equal to 3. |
Argument | One of the dimensions in shape is less than zero. |
CreateFromFunction<T>(TensorShape, Func<Int32, Int32, Int32, Int32, T>, TensorElementOrder, ArrayMutability)
Creates a new 4-dimensional tensor and initializes the elements
using the specified function.
public static Tensor<T> CreateFromFunction<T>(
TensorShape shape,
Func<int, int, int, int, T> function,
TensorElementOrder order = TensorElementOrder.CStyle,
ArrayMutability mutability = ArrayMutability.MutableValues
)
Parameters
- shape TensorShape
- The dimensions of the new tensor.
- function Func<Int32, Int32, Int32, Int32, T>
- A function that computes the value of the tensor element for the specified index.
- order TensorElementOrder (Optional)
- Optional. Specifies the element order of the result. By default, elements are stored in C-style (row-major) order.
- mutability ArrayMutability (Optional)
- Optional. Specifies how the tensor's values may be changed. The default is mutable values.
Type Parameters
- T
- The type of the elements of the tensor.
Return Value
Tensor<T>A 4D tensor with shape shape initialized using function.
Exceptions
Argument | function is null. |
Dimension | The rank of shape is not equal to 4. |
Argument | One of the dimensions in shape is less than zero. |