Click or drag to resize

DoubleMatrixDense Method (Double)

Creates a dense DoubleMatrix instance having the same size and data of the specified two-dimensional array.

Namespace:  Novacta.Analytics
Assembly:  Novacta.Analytics (in Novacta.Analytics.dll) Version: 2.0.0
Syntax
public static DoubleMatrix Dense(
	double[,] data
)

Parameters

data
Type: SystemDouble
The two-dimensional array containing matrix data.

Return Value

Type: DoubleMatrix
The matrix having the specified size and data.
Exceptions
ExceptionCondition
ArgumentNullExceptiondata is null.
ArgumentExceptiondata has at least a dimension along which the number of elements is zero.
Remarks

DoubleMatrix dense instances allocate storage for each matrix entry. Sparse DoubleMatrix instances can be created by calling method Sparse(Int32, Int32, Int32).

Examples

In the following example, some dense matrices are created from two-dimensional arrays.

Creation of dense matrices from two-dimensional arrays
using System;

namespace Novacta.Analytics.CodeExamples
{
    public class DenseExample6  
    {            
        public void Main()
        {
            // Set matrix dimensions.
            const int numberOfRows = 3;
            const int numberOfColumns = 2;

            // Create the data as an array having lower bounds equal to zero.
            var data = new double[numberOfRows, numberOfColumns]
                { { 1, 2 }, 
                  { 3, 4 }, 
                  { 5, 6 } };

            // Create the matrix. 
            var matrix = DoubleMatrix.Dense(data);
            Console.WriteLine("Creating from an array having zero lower bounds.");
            Console.WriteLine("The data matrix:");
            Console.WriteLine(matrix);

            Console.WriteLine();

            // Create the data as an array having non-zero lower bounds.
            int[] lowerBounds = { 2005, 1 };
            int[] lengths = { numberOfRows, numberOfColumns };
            data = (double[,])Array.CreateInstance(typeof(double),
                    lengths, lowerBounds);

            data[2005, 1] = 1.0; data[2005, 2] = 2.0; 
            data[2006, 1] = 3.0; data[2006, 2] = 4.0; 
            data[2007, 1] = 5.0; data[2007, 2] = 6.0;

            // Create the matrix. 
            matrix = DoubleMatrix.Dense(data);
            Console.WriteLine("Creating from an array having non-zero lower bounds.");
            Console.WriteLine("The data matrix:");
            Console.WriteLine(matrix);
        }
    }
}

// Executing method Main() produces the following output:
// 
// Creating from an array having zero lower bounds.
// The data matrix:
// 1                2                
// 3                4                
// 5                6                
// 
// 
// 
// Creating from an array having non-zero lower bounds.
// The data matrix:
// 1                2                
// 3                4                
// 5                6                
// 

See Also