DoubleMatrixItem Property (String, Int32) |
Namespace: Novacta.Analytics
Exception | Condition |
---|---|
ArgumentNullException | rowIndexes is null. -or- value is null. |
ArgumentOutOfRangeException | rowIndexes is not a string reserved for
collection sub-referencing. -or- columnIndex is less than zero. -or- columnIndex is greater than or equal to the number of columns of this instance. |
ArgumentException |
The number of rows in value is not equal to
the to the number of rows of this instance. -or- The number of columns in value is greater than 1. |
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.
In the following example, some matrix elements are simultaneously accessed.
using System; namespace Novacta.Analytics.CodeExamples { public class MatrixIndexerExample20 { 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 all row indexes. var rowIndexes = ":"; Console.WriteLine(); Console.WriteLine("Row indexes: from 0 to {0}", matrix.NumberOfRows - 1); // Specify a column index. int columnIndex = 0; Console.WriteLine(); Console.WriteLine("Column index: {0}", columnIndex); // Specify the value matrix. var valueData = new double[4] { -10, -20, -30, -40 }; var value = DoubleMatrix.Dense(4, 1, valueData, StorageOrder.RowMajor); Console.WriteLine(); Console.WriteLine("Value matrix:"); Console.WriteLine(value); // Set the entries having the specified indexes to the value matrix. matrix[rowIndexes, columnIndex] = 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[rowIndexes, columnIndex]); } } } // Executing method Main() produces the following output: // // Initial data matrix: // 1 5 9 // 2 6 10 // 3 7 11 // 4 8 12 // // // // Row indexes: from 0 to 3 // // Column index: 0 // // Value matrix: // -10 // -20 // -30 // -40 // // // // Updated data matrix: // -10 5 9 // -20 6 10 // -30 7 11 // -40 8 12 // // // // Updated matrix entries: // -10 // -20 // -30 // -40 //