Click or drag to resize

StatMean Method (ReadOnlyDoubleMatrix)

Returns the arithmetic mean of the specified data.

Namespace:  Novacta.Analytics
Assembly:  Novacta.Analytics (in Novacta.Analytics.dll) Version: 2.0.0
Syntax
public static double Mean(
	ReadOnlyDoubleMatrix data
)

Parameters

data
Type: Novacta.AnalyticsReadOnlyDoubleMatrix
The data.

Return Value

Type: Double
The arithmetic mean of the specified data.
Exceptions
ExceptionCondition
ArgumentNullExceptiondata is null.
Remarks

This method returns the arithmetic mean of the data entries. Let us define

LaTeX equation

where LaTeX equation is the data length. Then the returned value can be represented by the expression

LaTeX equation

Examples

In the following example, the arithmetic mean of a data matrix is computed.

C#
using System;

namespace Novacta.Analytics.CodeExamples
{
    public class MeanExample1  
    {
        public void Main()
        {
            // Create a matrix.
            var data = new double[6] {
                1, 2,
                2, 3,
                3, 4
            };
            var matrix = DoubleMatrix.Dense(3, 2, data, StorageOrder.RowMajor);
            Console.WriteLine("The data matrix:");
            Console.WriteLine(matrix);

            // Compute the data mean.
            var mean = Stat.Mean(matrix);

            Console.WriteLine();
            Console.WriteLine("Data mean is:");
            Console.WriteLine(mean);

            // Mean is overloaded to accept data as a read-only matrix:
            // compute the mean using a read-only wrapper of the data matrix.
            ReadOnlyDoubleMatrix readOnlyMatrix = matrix.AsReadOnly();
            var meanOfReadOnlyData = Stat.Mean(readOnlyMatrix);

            Console.WriteLine();
            Console.WriteLine("Using read-only data. The mean is:");
            Console.WriteLine(meanOfReadOnlyData);
        }
    }
}

// Executing method Main() produces the following output:
// 
// The data matrix:
// 1                2                
// 2                3                
// 3                4                
// 
// 
// 
// Data mean is:
// 2.5
// 
// Using read-only data. The mean is:
// 2.5

See Also