How to get a sub matrix from a multi dimensional array in Math.Net?

162 views Asked by At

I'm new to Math.Net. Let's say I have a multi-dimensional matrix as:

double [,,] matA = new double [2,3,3];

for(k = 0; k < 2; k++)
{
   for(i = 0; i < 3; i++)
   {
      for(j = 0 ;j < 3; j++)
      {
        matA[k,i,j] = ... // assign some value
      }
   }
}

I want to find the transpose of "matA[0,All,All]" and "matA[1,All,All]" where the "All" pseudo-syntax is from Mathematica which is useful, however, I don't know how to extract the [0,All,All] or [1,All,All] matrices in Math.Net.

I appreciate any help and advice about how to extract a specific part of the multi-dimensional matrix in Math.Net.

I have copied the matrix defined above as "matA" into "matAnew" as follows:

Matrix<double> matAnew = DenseMatrix.OfArray(matA);

matAnew.SubMatrix(?,?,?,?)

I have an intuition that the SubMatrix method in Math.Net can be used for it but I'm not sure how could it be done.

1

There are 1 answers

0
Jay Makhija On

Just a Suggesting answer, it is bit confusing

The SubMatrix method is used to extract a submatrix from matAnew. The method takes four arguments: rowStart, rowCount, columnStart, and columnCount.

The rowStart specifies the starting row index for the submatrix.

The rowCount specifies the number of rows in the submatrix.

The columnStart specifies the starting column index for the submatrix.

The columnCount specifies the number of columns in the submatrix.

matAnew.SubMatrix(matAnew.RowStart, matAnew.RowCount, matAnew.ColumnStart, matAnew.ColumnCount);
Matrix<double> matAnew = DenseMatrix.OfArray(matA);

// Extract specific submatrices
Matrix<double> subMatrix0 = matAnew.SubMatrix(0, 1, 0, matAnew.ColumnCount);
Matrix<double> subMatrix1 = matAnew.SubMatrix(1, 1, 0, matAnew.ColumnCount);