-2
  • Vectors contains one column, m rows : each row contains an array of n floats;
  • I want to have a m x n matrix, transpose it and do there product
  • I'm using C#

Also, I read this from official documentation https://numerics.mathdotnet.com/Matrix.html

"For example, if you have a collection of vectors, consider to store them in a list or array of vectors, not in a matrix (unless you need matrix operations, of course)."

So please what's the optimized way to achieve this with Math.net.numerics? Thanks in advance

#UPDATE

I'm getting this Error

CS1503  Argument 3: cannot convert from'System.Collections.Generic.IEnumerable<float[]>' to 'float[]'

With this code :

IEnumerable<float[]> Vectors = predictions.GetColumn<float[]>("Features");
var x = new M.DenseMatrix(1, Vectors.Count(), Vectors);

1 Answers1

1

Solved

var Matrix = M.SparseMatrix.OfColumnArrays(Vectors);

Details :

public Matrix<T> SparseOfColumnArrays(IEnumerable<T[]> columns);

is expecting the same type of vector with T=float, so it worked. I suggest you read the library methods from your IDE. 2- As the matrix is not dense I switched to Sparse.

  • Thanks for posting the answer! Can you please try and explain *why* this fixes the error and what was the mistake in the original code in the question? – omajid Jul 16 '20 at 18:01
  • `public Matrix SparseOfColumnArrays(IEnumerable columns);`is expecting the same type of vector with T=float, so it worked. I suggest you read the library methods from your IDE. 2- As the matrix is not dense I switched to Sparse. – Ania Berthelot Jul 17 '20 at 10:59
  • Please put the explanation in the answer :) Thanks! – omajid Jul 17 '20 at 13:20
  • 1
    How do you feel now? @omajid :) TBH I'm not happy with what's going on here. I had a real issue that I resolved and even shared my solution, so people can save time. But I don't know why this post is getting -4 score? It's really unfair and discouraging – Ania Berthelot Jul 17 '20 at 15:55
  • I think part of that is the StackOverflow culture and expectations. People look at answers and downvote (or worse, propose for deletion) if the answer is just code. See https://meta.stackoverflow.com/questions/300694/what-to-do-with-code-only-answers-in-low-quality-posts-queue and https://meta.stackoverflow.com/questions/300837/what-comment-should-i-add-to-code-only-answers. Adding an explanation will help get you a higher score! – omajid Jul 17 '20 at 16:06
  • 2
    This is giving power to mindless bureaucratic "bots" or worse cyborgs. I detailed my answer, edited my post many times just for the sake of helping others. I showed my good will. On the other hand, I had no added value from all this as I found the solution my self, and wasted time/energy dealing with people's fantasms here. I'm new here, and this experience is just frustrating, worse communication is part of it. @omajid – Ania Berthelot Jul 18 '20 at 10:15