-3

I have a question for you. I created a matrix in C# doing some mathematical operations using Math.Net. Now I would like to transform the matrix in a List or split its columns in more arrays. My goal is to pass this matrix to a software which doesn't read matrices from Math.Net but only reads lists, arrays and so on from C# codes.

Thank you!

EDIT: Here's my code:

Matrix<double>[] matrixC = new Matrix<double>[ins];
            for (int i = 0; i < ins; i++)
            {
                matrixC[i] = Matrix<double>.Build.DenseOfColumns(CjTR[i]);
            }

matrixC is a matrix of matrices created assembling some lists. Here's my matrixC.

matrixC[0]

enter image description here

matrixC1

enter image description here

I'd like to know if it possible to split each column in arrays or list. Not Math.Net matrix anymore.

  • Provide a link to documentation for the Math.Net matrix class you have an instance of. We can't guess which one you have. – Ben Voigt Aug 04 '19 at 14:31
  • Can you elaborate on how your code "doesn't work"? What were you expecting, and what actually happened? If you got an exception/error, post the line it occurred on and the exception/error details which can be done with a [mre]. Please [edit] your question to add these details into it or we may not be able to help. – Patrick Artner Aug 04 '19 at 15:49

1 Answers1

0

Standard 2d matrix (or at least its data) is nothing more than a regular 2d array or an array of arrays.

Both those representation can be created with standard Math.Net methods on the Matrix class:

var matrix = MathNet.Numerics.LinearAlgebra.Matrix<double>.Build.Random(3, 4);
var matrixAs2DArray = matrix.ToArray();
var matrixAsJaggedArrayPerColumn = matrix.ToColumnArrays();
var matrixAsJaggedArrayPerRow = matrix.ToRowArrays();

If you need to use lists/IList instead of arrays, then it can be done using Conversion of System.Array to List

If you want to totally avoid Math.Net classes then you just have to create such arrays manually.

P.S.: In some cases it may make sense to use IDictionary<(int row,int column), TValue> as a way to represent a (especially sparse) matrix, but that is slightly different question.

Eugene Podskal
  • 10,270
  • 5
  • 31
  • 53