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#
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

C#
// 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

ArgumentOutOfRangeExceptionlength is less than zero.

See Also