Click or drag to resize

DoubleMatrixTranspose Method

Returns the transpose of this instance.

Namespace:  Novacta.Analytics
Assembly:  Novacta.Analytics (in Novacta.Analytics.dll) Version: 2.0.0
Syntax
public DoubleMatrix Transpose()

Return Value

Type: DoubleMatrix
The transpose of this instance.
Remarks

Let LaTeX equation and LaTeX equation be the number of rows and columns, respectively, of this instance, and consider its generic entry

LaTeX equation

The method returns the transpose of this instance, i.e. a matrix, say LaTeX equation, having LaTeX equation rows and LaTeX equation columns, whose generic entry is:

LaTeX equation

Examples

In the following example, the transpose of a matrix is computed.

C#
using System;

namespace Novacta.Analytics.CodeExamples
{
    public class OutPlaceTransposeExample0  
    {
        public void Main()
        {
            // Create a matrix.
            var data = new double[20] {
                1, 8, -3,  6, -2,
                2, 2,  2,  0,  7,
               -3, 9,  3,  2,  9,
                5, 2, -5, -1, -4
            };
            var matrix = DoubleMatrix.Dense(4, 5, data, StorageOrder.RowMajor);
            Console.WriteLine("The data matrix:");
            Console.WriteLine(matrix);

            // Return its transpose.
            var transposedMatrix = matrix.Transpose();

            Console.WriteLine();
            Console.WriteLine("Matrix transpose:");
            Console.WriteLine(transposedMatrix);

            // Compute the transpose using a read-only wrapper of the data matrix.
            ReadOnlyDoubleMatrix readOnlyMatrix = matrix.AsReadOnly();
            var transposedReadOnlyMatrix = readOnlyMatrix.Transpose();

            Console.WriteLine();
            Console.WriteLine("Read only matrix transpose:");
            Console.WriteLine(transposedReadOnlyMatrix);
        }
    }
}

// Executing method Main() produces the following output:
// 
// The data matrix:
// 1                8                -3               6                -2               
// 2                2                2                0                7                
// -3               9                3                2                9                
// 5                2                -5               -1               -4               
// 
// 
// 
// Matrix transpose:
// 1                2                -3               5                
// 8                2                9                2                
// -3               2                3                -5               
// 6                0                2                -1               
// -2               7                9                -4               
// 
// 
// 
// Read only matrix transpose:
// 1                2                -3               5                
// 8                2                9                2                
// -3               2                3                -5               
// 6                0                2                -1               
// -2               7                9                -4               
// 

See Also