Vector.Ones<T> Method
Constructs a new vector with all elements initialized to one.
Definition
Namespace: Numerics.NET
Assembly: Numerics.NET (in Numerics.NET.dll) Version: 10.1.0
C#
A ConstantVector<T> with all elements set to one if mutability is Immutable, or a DenseVector<T> otherwise.
Assembly: Numerics.NET (in Numerics.NET.dll) Version: 10.1.0
public static Vector<T> Ones<T>(
int length,
ArrayMutability mutability = ArrayMutability.Immutable
)
Parameters
- length Int32
- The length of the vector.
- mutability ArrayMutability (Optional)
- Specifies how the vector's values may be changed. The default is immutable (constant vector).
Type Parameters
- T
- The element type of the vector.
Return Value
Vector<T>A ConstantVector<T> with all elements set to one if mutability is Immutable, or a DenseVector<T> otherwise.
Example
// Create a constant vector of 5 ones
var ones = Vector.Ones<double>(5);
// Create a mutable vector of 5 ones
var mutableOnes = Vector.Ones<double>(5, ArrayMutability.MutableValues);Exceptions
| Argument | length is less than zero. |