Matrix.Ones Like<T> Method
Creates a new matrix with the same shape as the template, initialized to one.
Definition
Namespace: Numerics.NET
Assembly: Numerics.NET (in Numerics.NET.dll) Version: 10.1.0
C#
A ConstantMatrix<T> with the same shape as template, initialized to one if mutability is Immutable, or a DenseMatrix<T> otherwise.
Assembly: Numerics.NET (in Numerics.NET.dll) Version: 10.1.0
public static Matrix<T> OnesLike<T>(
Matrix<T> template,
ArrayMutability mutability = ArrayMutability.Immutable
)
Parameters
- template Matrix<T>
- The matrix whose shape to copy.
- 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 the same shape as template, initialized to one if mutability is Immutable, or a DenseMatrix<T> otherwise.
Example
var original = Matrix.Random(3, 4);
var ones = Matrix.OnesLike(original); // 3x4 matrix of onesExceptions
| Argument | template is null. |