DoubleMatrixVec Method |
Namespace: Novacta.Analytics
Let be a matrix, and consider its generic entry
where and
are the
number of rows and columns of , respectively.
A linear index completely
identifies an entry,
assuming that entries are linearly ordered following the
ColumnMajor
data order. This means that entry has linear
index equal to , and matrix entries can be enumerated as
follows:
where is the Count of the matrix.
This method, when called on a DoubleMatrix instance
representing matrix , returns a new
DoubleMatrix instance that
represents a column vector, say ,
such that:
In the following example, a matrix is vectorized.
using System; namespace Novacta.Analytics.CodeExamples { public class VecExample0 { 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 vectorization of the data matrix. var vectorized = matrix.Vec(); Console.WriteLine(); Console.WriteLine("Vectorized data matrix:"); Console.WriteLine(vectorized); // Entries can also be vectorized using a read-only wrapper of the matrix. ReadOnlyDoubleMatrix readOnlyMatrix = matrix.AsReadOnly(); Console.WriteLine(); Console.WriteLine("Vectorized read-only data matrix :"); Console.WriteLine(readOnlyMatrix.Vec()); } } } // Executing method Main() produces the following output: // // Initial data matrix: // 1 2 3 // 4 5 6 // 7 8 9 // // // // Vectorized data matrix: // 1 // 4 // 7 // 2 // 5 // 8 // 3 // 6 // 9 // // // // Vectorized read-only data matrix : // 1 // 4 // 7 // 2 // 5 // 8 // 3 // 6 // 9 //