Click or drag to resize

DoubleMatrixItem Property (Int32, IndexCollection)

Gets or sets the elements of this instance corresponding to the specified row and column indexes.

Namespace:  Novacta.Analytics
Assembly:  Novacta.Analytics (in Novacta.Analytics.dll) Version: 2.0.0
Syntax
public DoubleMatrix this[
	int rowIndex,
	IndexCollection columnIndexes
] { get; set; }

Parameters

rowIndex
Type: SystemInt32
The zero-based row index of the elements to get or set.
columnIndexes
Type: Novacta.AnalyticsIndexCollection
The zero-based column indexes of the elements to get or set.

Property Value

Type: DoubleMatrix
A tabular collection formed by the elements corresponding to the specified row and column indexes.

Implements

IReadOnlyTabularCollectionTValue, TCollectionItemInt32, IndexCollection
ITabularCollectionTValue, TCollectionItemInt32, IndexCollection
Exceptions
ExceptionCondition
ArgumentNullExceptioncolumnIndexes is null.
-or-
value is null.
ArgumentOutOfRangeExceptionrowIndex is less than zero.
-or-
rowIndex is greater than or equal to the number of rows of this instance. -or-
columnIndexes contains an index which is greater than or equal to the number of columns of this instance.
ArgumentException The number of rows in value is greater than 1.
-or-
The number of columns in value is not equal to the Count of columnIndexes.
Remarks

When setting elements simultaneously, the value must be a tabular collection having a number of rows equal to the number of specified row indexes, and a number of columns equal to the number of specified column indexes.

Examples

In the following example, some matrix elements are simultaneously accessed.

C#
using System;

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

            // Specify a row index.
            int rowIndex = 1;
            Console.WriteLine();
            Console.WriteLine("Row index: {0}", rowIndex);

            // Specify some column indexes.
            var columnIndexes = IndexCollection.Sequence(0,2,2);
            Console.WriteLine();
            Console.WriteLine("Column indexes: {0}", columnIndexes);

            // Specify the value matrix.
            var valueData = new double[2] {
                -20, -100
            };
            var value = DoubleMatrix.Dense(1, 2, valueData, StorageOrder.RowMajor);
            Console.WriteLine();
            Console.WriteLine("Value matrix:");
            Console.WriteLine(value);

            // Set the entries having the specified indexes to the value matrix.
            matrix[rowIndex, columnIndexes] = value;

            Console.WriteLine();
            Console.WriteLine("Updated data matrix:");
            Console.WriteLine(matrix);

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

            Console.WriteLine();
            Console.WriteLine("Updated matrix entries:");
            Console.WriteLine(readOnlyMatrix[rowIndex, columnIndexes]);
        }
    }
}

// Executing method Main() produces the following output:
// 
// Initial data matrix:
// 1                5                9                
// 2                6                10               
// 3                7                11               
// 4                8                12               
// 
// 
// 
// Row index: 1
// 
// Column indexes: 0, 2
// 
// Value matrix:
// -20              -100             
// 
// 
// 
// Updated data matrix:
// 1                5                9                
// -20              6                -100             
// 3                7                11               
// 4                8                12               
// 
// 
// 
// Updated matrix entries:
// -20              -100             
// 

See Also