Click or drag to resize

DoubleMatrixVec Method (IndexCollection)

Returns a column vector obtained by stacking the specified elements of this instance.

Namespace:  Novacta.Analytics
Assembly:  Novacta.Analytics (in Novacta.Analytics.dll) Version: 2.0.0
Syntax
public DoubleMatrix Vec(
	IndexCollection linearIndexes
)

Parameters

linearIndexes
Type: Novacta.AnalyticsIndexCollection
The linear indexes of the elements to stack.

Return Value

Type: DoubleMatrix
A column vector obtained by stacking the specified elements of this instance.
Exceptions
ExceptionCondition
ArgumentNullExceptionlinearIndexes is null.
ArgumentOutOfRangeExceptionlinearIndexes contains an index which is greater than or equal to the Count of this instance.
Remarks

Let LaTeX equation be a matrix, and consider its generic entry

LaTeX equation

where LaTeX equation and LaTeX equation are the number of rows and columns of LaTeX equation, respectively.

A linear index completely identifies an entry, assuming that entries are linearly ordered following the ColumnMajor data order. This means that entry LaTeX equation has linear index equal to LaTeX equation, and matrix entries can be enumerated as follows:

LaTeX equation

where LaTeX equation is the Count of the matrix.

Let LaTeX equation the collection of indexes represented by linearIndexes. This method, when called on a DoubleMatrix instance representing matrix LaTeX equation, returns a new DoubleMatrix instance that represents a column vector, say LaTeX equation, such that:

LaTeX equation

Examples

In the following example, some matrix entries are vectorized.

C#
using System;

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

            // Get the linear indexes of elements on
            // the main diagonal.
            var mainDiagonalIndexes = IndexCollection.Sequence(0, 4, 10);

            // Get the vectorization of the matrix main diagonal.
            var mainDiagonal = matrix.Vec(mainDiagonalIndexes);

            Console.WriteLine();
            Console.WriteLine("Vectorized main diagonal:");
            Console.WriteLine(mainDiagonal);

            // Entries can also be vectorized using a read-only wrapper of the matrix.
            ReadOnlyDoubleMatrix readOnlyMatrix = matrix.AsReadOnly();

            Console.WriteLine();
            Console.WriteLine("Vectorized main diagonal of a read-only data matrix:");
            Console.WriteLine(readOnlyMatrix.Vec(mainDiagonalIndexes));
        }
    }
}

// Executing method Main() produces the following output:
// 
// Initial data matrix:
// 1                2                3                
// 4                5                6                
// 7                8                9                
// 
// 
// 
// Vectorized main diagonal:
// 1                
// 5                
// 9                
// 
// 
// 
// Vectorized main diagonal of a read-only data matrix:
// 1                
// 5                
// 9                
// 

See Also