Click or drag to resize

DoubleMatrixFromIndexPartition Method

Namespace:  Novacta.Analytics
Assembly:  Novacta.Analytics (in Novacta.Analytics.dll) Version: 2.0.0
Syntax
public static DoubleMatrix FromIndexPartition(
	IndexPartition<double> value
)

Parameters

value
Type: Novacta.AnalyticsIndexPartitionDouble
The object to convert.

Return Value

Type: DoubleMatrix
The converted object.
Exceptions
ExceptionCondition
ArgumentNullExceptionvalue is null.
Remarks

The partition is converted to a column vector whose row indexes are partitioned following the different parts of value, so that the rows whose indexes are in a given part will be filled with the identifier of such part.

Examples

In the following example, an index partition having doubles as part identifiers is converted to a matrix.

C#
using System;

namespace Novacta.Analytics.CodeExamples
{
    public class IndexPartitionExample6  
    {
        public void Main()
        {
            // Create a matrix.
            var data = new double[6] {
                1,3,
                0,2,
                2,1
            };
            var matrix = DoubleMatrix.Dense(3, 2, data, StorageOrder.RowMajor);

            // Partition the matrix linear indexes by the content of 
            // matrix entries: a part is created for each distinct matrix value.
            var partition = IndexPartition.Create(matrix);

            // Each part is identified by its corresponding value and contains
            // the linear indexes of the entries in which the identifier
            // is positioned.
            Console.WriteLine();
            foreach (var identifier in partition.Identifiers)
            {
                Console.WriteLine("Part identifier: {0}", identifier);
                Console.WriteLine("     indexes: {0}", partition[identifier]);
                Console.WriteLine();
            }

            // Convert the partition to a matrix.
            var fromPartition = DoubleMatrix.FromIndexPartition(partition);
            Console.WriteLine("Conversion of a partition to a matrix:");
            Console.WriteLine(fromPartition);
        }
    }
}

// Executing method Main() produces the following output:
// 
// 
// Part identifier: 0
//      indexes: 1
// 
// Part identifier: 1
//      indexes: 0, 5
// 
// Part identifier: 2
//      indexes: 2, 4
// 
// Part identifier: 3
//      indexes: 3
// 
// Conversion of a partition to a matrix:
// 1                
// 0                
// 2                
// 3                
// 2                
// 1                
// 

See Also