Click or drag to resize

StatMean Method (DoubleMatrix, DataOperation)

Returns the arithmetic mean of each row or column in the specified data.

Namespace:  Novacta.Analytics
Assembly:  Novacta.Analytics (in Novacta.Analytics.dll) Version: 2.0.0
Syntax
public static DoubleMatrix Mean(
	DoubleMatrix data,
	DataOperation dataOperation
)

Parameters

data
Type: Novacta.AnalyticsDoubleMatrix
The data.
dataOperation
Type: Novacta.AnalyticsDataOperation
A constant to specify if the arithmetic mean is to be computed for rows or columns.

Return Value

Type: DoubleMatrix
The arithmetic mean of each row or column in the specified data.
Exceptions
ExceptionCondition
ArgumentNullExceptiondata is null.
ArgumentExceptiondataOperation is not a field of DataOperation.
Remarks

This method returns the arithmetic mean of data rows or columns. Let LaTeX equation and LaTeX equation be the data number of rows and columns, respectively, and define

LaTeX equation

Operating on rows

If dataOperation is OnRows, then the method returns a column vector whose length equals the number of rows of data. The i-th entry of the returned column exposes the arithmetic mean of the i-th data row.

The arithmetic mean of the i-th row can be represented by the expression

LaTeX equation

Operating on columns

If dataOperation is OnColumns, then the method returns a row vector whose length is the data number of columns. The j-th entry of the returned row exposes the mean of the j-th data column.

The arithmetic mean of the j-th column can be represented by the expression

LaTeX equation

Examples

In the following example, row and column arithmetic means in a data matrix are computed.

C#
using System;

namespace Novacta.Analytics.CodeExamples
{
    public class MeanExample0  
    {
        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 mean on columns.
            var meanOnColumns = Stat.Mean(matrix, DataOperation.OnColumns);

            Console.WriteLine();
            Console.WriteLine("Mean on columns:");
            Console.WriteLine(meanOnColumns);

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

            Console.WriteLine();
            Console.WriteLine("Mean on rows:");
            Console.WriteLine(meanOnRows);
        }
    }
}

// Executing method Main() produces the following output:
// 
// The data matrix:
// 1                2                
// 2                3                
// 3                4                
// 
// 
// 
// Mean on columns:
// 2                3                
// 
// 
// 
// Mean on rows:
// 1.5              
// 2.5              
// 3.5              
// 

See Also