StatMax Method (ReadOnlyDoubleMatrix, DataOperation) |
Namespace: Novacta.Analytics
public static IndexValuePair[] Max( ReadOnlyDoubleMatrix data, DataOperation dataOperation )
Exception | Condition |
---|---|
ArgumentNullException | data is null. |
ArgumentException | dataOperation is not a field of DataOperation. |
Operating on rows
If dataOperation is OnRows, then the method returns an array of IndexValuePair structures, one for each row in data. The i-th array entry exposes the maximum value in the i-th row through property Value, while the corresponding first column position in the row can be inspected by getting property Index.
Operating on columns
If dataOperation is OnColumns, then the method returns an array of IndexValuePair structures, one for each column in data. The j-th array entry exposes the maximum value in the j-th column through property Value, while the corresponding first row position in the column can be inspected by getting property Index.
In the following example, row and column largest entries of the specified data are computed.
using System; namespace Novacta.Analytics.CodeExamples { public class MaxExample0 { 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); // Return the largest entries in columns of the specified data. var columnMaxs = Stat.Max(matrix, DataOperation.OnColumns); Console.WriteLine(); for (int j = 0; j < matrix.NumberOfColumns; j++) { Console.WriteLine("Column {0}: maximum is {1} on row {2}", j, columnMaxs[j].Value, columnMaxs[j].Index); } // Max is overloaded to accept data as a read-only matrix: // return the largest entries in rows using a read-only wrapper of // the data matrix. ReadOnlyDoubleMatrix readOnlyMatrix = matrix.AsReadOnly(); var rowMaxs = Stat.Max(readOnlyMatrix, DataOperation.OnRows); Console.WriteLine(); for (int i = 0; i < readOnlyMatrix.NumberOfRows; i++) { Console.WriteLine("Row {0}: maximum is {1} on column {2}", i, rowMaxs[i].Value, rowMaxs[i].Index); } } } } // Executing method Main() produces the following output: // // The data matrix: // -1 -2 // 2 3 // 3 -4 // // // // Column 0: maximum is 3 on row 2 // Column 1: maximum is 3 on row 1 // // Row 0: maximum is -1 on column 0 // Row 1: maximum is 3 on column 1 // Row 2: maximum is 3 on column 0