numl.Math.LinearAlgebra.Matrix.Sum C# (CSharp) Method

Sum() public static method

Computes the sum of every element of the matrix.
public static Sum ( Matrix m ) : double
m Matrix Input Matrix.
return double
        public static double Sum(Matrix m)
        {
            double sum = 0;
            for (int i = 0; i < m.Rows; i++)
                for (int j = 0; j < m.Cols; j++)
                    sum += m[i, j];
            return sum;
        }

Same methods

Matrix::Sum ( Matrix m, VectorType t ) : Vector
Matrix::Sum ( Matrix m, int i, VectorType t ) : double

Usage Example

示例#1
0
        /// <summary>Estimates.</summary>
        /// <param name="X">The Matrix to process.</param>
        /// <param name="type">(Optional) the type.</param>
        public void Estimate(Matrix X, VectorType type = VectorType.Row)
        {
            int n = type == VectorType.Row ? X.Rows : X.Cols;
            int s = type == VectorType.Row ? X.Cols : X.Rows;
            Mu = X.Sum(type) / n;
            Sigma = Matrix.Zeros(s);
            
            for (int i = 0; i < n; i++)
            {
                var x = X[i, type] - Mu;
                Sigma += x.Outer(x);
            }

            Sigma *= (1d / (n - 1d));
        }
All Usage Examples Of numl.Math.LinearAlgebra.Matrix::Sum