Matrix.RandomNormal Method

Definition

Namespace: Numerics.NET
Assembly: Numerics.NET (in Numerics.NET.dll) Version: 10.1.0

Overload List

RandomNormal(Int32, Int32, Double, Double, ArrayMutability) Creates a new matrix with normally distributed random numbers.
RandomNormal(Int32, Int32, Double, Double, Random, ArrayMutability) Creates a new matrix with normally distributed random numbers.

RandomNormal(Int32, Int32, Double, Double, ArrayMutability)

Creates a new matrix with normally distributed random numbers.
C#
public static DenseMatrix<double> RandomNormal(
	int rowCount,
	int columnCount,
	double mean = 0,
	double standardDeviation = 1,
	ArrayMutability mutability = ArrayMutability.MutableValues
)

Parameters

rowCount  Int32
The number of rows in the new matrix.
columnCount  Int32
The number of columns in the new matrix.
mean  Double  (Optional)
The mean of the normal distribution.
standardDeviation  Double  (Optional)
The standard deviation of the normal distribution.
mutability  ArrayMutability  (Optional)
Specifies how the matrix's values may be changed. The default is mutable values.

Return Value

DenseMatrix<Double>
A new DenseMatrix<T> with random values from a normal distribution with the specified mean and standard deviation.

Example

C#
// Create a 3x4 matrix with values from N(0, 1)
var m = Matrix.RandomNormal(3, 4, 0.0, 1.0);

Exceptions

ArgumentOutOfRangeExceptionrowCount or columnCount is less than zero, or standardDeviation is less than or equal to zero.

RandomNormal(Int32, Int32, Double, Double, Random, ArrayMutability)

Creates a new matrix with normally distributed random numbers.
C#
public static DenseMatrix<double> RandomNormal(
	int rowCount,
	int columnCount,
	double mean,
	double standardDeviation,
	Random random,
	ArrayMutability mutability = ArrayMutability.MutableValues
)

Parameters

rowCount  Int32
The number of rows in the new matrix.
columnCount  Int32
The number of columns in the new matrix.
mean  Double
The mean of the normal distribution.
standardDeviation  Double
The standard deviation of the normal distribution.
random  Random
A random number generator used to generate samples.
mutability  ArrayMutability  (Optional)
Specifies how the matrix's values may be changed. The default is mutable values.

Return Value

DenseMatrix<Double>
A new DenseMatrix<T> with random values from a normal distribution with the specified mean and standard deviation.

Example

C#
// Create a reproducible 3x4 matrix with values from N(5, 2)
var rng = new Random(42);
var m = Matrix.RandomNormal(3, 4, 5.0, 2.0, rng);

Exceptions

ArgumentOutOfRangeExceptionrowCount or columnCount is less than zero, or standardDeviation is less than or equal to zero.
ArgumentNullExceptionrandom is null.

See Also