Click or drag to resize

StatSort Method (DoubleMatrix, SortDirection)

Sorts the specified data in ascending or descending order.

Namespace:  Novacta.Analytics
Assembly:  Novacta.Analytics (in Novacta.Analytics.dll) Version: 2.0.0
Syntax
public static DoubleMatrix Sort(
	DoubleMatrix data,
	SortDirection sortDirection
)

Parameters

data
Type: Novacta.AnalyticsDoubleMatrix
The data.
sortDirection
Type: Novacta.AnalyticsSortDirection
A constant to specify if to sort in ascending or descending order.

Return Value

Type: DoubleMatrix
The sorted data.
Exceptions
ExceptionCondition
ArgumentNullExceptiondata is null.
ArgumentExceptionsortDirection is not a field of SortDirection.
Remarks

This method returns a matrix having the same dimensions of data. The entry occupying the l-th linear position of the returned matrix is the entry of the original matrix occupying the l-th position in the requested ordering.

Examples

In the following example, a data matrix is sorted.

C#
using System;

namespace Novacta.Analytics.CodeExamples
{
    public class SortExample0  
    {
        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);

            // Sort the data in ascending order.
            var sortedData = Stat.Sort(matrix, SortDirection.Ascending);

            Console.WriteLine();
            Console.WriteLine("Data sorted in ascending order:");
            Console.WriteLine(sortedData);

            // Sort is overloaded to accept data as a read-only matrix:
            // sort in descending order using a read-only wrapper of the data matrix.
            ReadOnlyDoubleMatrix readOnlyMatrix = matrix.AsReadOnly();
            var sortedReadOnlyData = Stat.Sort(readOnlyMatrix, SortDirection.Descending);

            Console.WriteLine();
            Console.WriteLine("Using read-only data. Descending sort:");
            Console.WriteLine(sortedReadOnlyData);
        }
    }
}

// Executing method Main() produces the following output:
// 
// The data matrix:
// 1                2                
// 2                -3               
// 3                4                
// 
// 
// 
// Data sorted in ascending order:
// -3               2                
// 1                3                
// 2                4                
// 
// 
// 
// Using read-only data. Descending sort:
// 4                2                
// 3                1                
// 2                -3               
// 

See Also