Encog.MathUtil.Matrices.Matrix.Sum C# (CSharp) Method

Sum() public method

Sum all of the values in the matrix.
public Sum ( ) : double
return double
        public double Sum()
        {
            double result = 0;
            for (int r = 0; r < Rows; r++)
            {
                for (int c = 0; c < Cols; c++)
                {
                    result += matrix[r][c];
                }
            }
            return result;
        }

Usage Example

 public void Sum()
 {
     double[][] doubleData = {
                                 new[] {1.0, 2.0},
                                 new[] {3.0, 4.0}
                             };
     var matrix = new Matrix(doubleData);
     Assert.AreEqual((int) matrix.Sum(), 1 + 2 + 3 + 4);
 }