IndexPartitionCreate Method (DoubleMatrixRowCollection) |
Namespace: Novacta.Analytics
public static IndexPartition<DoubleMatrixRow> Create( DoubleMatrixRowCollection elements )
Exception | Condition |
---|---|
ArgumentNullException | elements is null. |
In the following example, the row indexes of a matrix are partitioned by the contents of its rows. Each part is identified by a distinct row, the part identifier, and contains the indexes of the rows which are equal to the identifier.
using System; namespace Novacta.Analytics.CodeExamples { public class IndexPartitionExample1 { public void Main() { // Create a matrix. var data = new double[18] { 0,0,1, 0,0,1, 0,1,0, 0,1,0, 1,0,0, 1,0,0 }; var matrix = DoubleMatrix.Dense(6, 3, data, StorageOrder.RowMajor); // Partition the matrix row indexes by the contents of each row: // a part is created for each distinct row. var partition = IndexPartition.Create(matrix.AsRowCollection()); // Each part is identified by its corresponding row and contains // the indexes of the rows which are equal to the identifier. Console.WriteLine(); foreach (var identifier in partition.Identifiers) { Console.WriteLine("Part identifier: {0}", identifier); Console.WriteLine(" indexes: {0}", partition[identifier]); Console.WriteLine(); } } } } // Executing method Main() produces the following output: // // // Part identifier: 0 0 1 // indexes: 0, 1 // // Part identifier: 0 1 0 // indexes: 2, 3 // // Part identifier: 1 0 0 // indexes: 4, 5