Matrix.Ones<T> Method

Creates a new matrix with all elements initialized to one.

Definition

Namespace: Numerics.NET
Assembly: Numerics.NET (in Numerics.NET.dll) Version: 10.1.0
C#
public static Matrix<T> Ones<T>(
	int rowCount,
	int columnCount,
	ArrayMutability mutability = ArrayMutability.Immutable
)

Parameters

rowCount  Int32
The number of rows in the new matrix.
columnCount  Int32
The number of columns in the new matrix.
mutability  ArrayMutability  (Optional)
Specifies how the matrix's values may be changed. The default is immutable (constant matrix).

Type Parameters

T
The element type of the matrix.

Return Value

Matrix<T>
A ConstantMatrix<T> with all elements set to one if mutability is Immutable, or a DenseMatrix<T> otherwise.

Example

C#
// Create a 3x4 constant matrix of ones
var ones = Matrix.Ones<double>(3, 4);

// Create a mutable 3x4 matrix of ones
var mutableOnes = Matrix.Ones<double>(3, 4, ArrayMutability.MutableValues);

Exceptions

ArgumentOutOfRangeExceptionrowCount or columnCount is less than zero.

See Also