Afshinzkh
Afshinzkh

Reputation: 109

Math.Net Numerics library Transpose doesn't Work

So I want to transpose a matrix that I defined with

using MathNet.Numerics.LinearAlgebra.Double;
     var MatrixValues = new double[]{1,1,2,2,3,3}
     var M = Matrix<double>.Build; 
     var C = M.Dense(3,2,MatrixValues);  
     var TR = C.Transpose();

So the result I get is a very strange matrix which is not the transpose. I think this is because the matrix is defined as DenseColumnMajor, but How can I change it?

So I have a 3 by 2 matrix like:

1 1
2 2 
3 3

and my desired result is:

1 2 3
1 2 3

Upvotes: 1

Views: 1687

Answers (1)

Christoph R&#252;egg
Christoph R&#252;egg

Reputation: 4736

Transpose works correctly in this case:

C:
DenseMatrix 3x2-Double
1  2
1  3
2  3

TR:
DenseMatrix 2x3-Double
1  1  2
2  3  3

As documented, the specific builder expects the array to be in column major order. There are quite a few ways to create matrices. If you cannot rearrange the array in column-major order, maybe another way works better for you. See Creating Matrices and Vectors.

Upvotes: 1

Related Questions