Reputation: 1269
I know this is going to sound like a very beginner question but I'm using this C# library and even after reading the references, I'm not able to figure out how to do the following code.
Matrix Class Documentation is at https://numerics.mathdotnet.com/api/MathNet.Numerics.LinearAlgebra/Matrix%601.htm
I'm trying to do something similar to this but I can't figure it out
Matrix<double> matrix = new Matrix<double>();
matrix.Add(new List<double> list1());
matrix.Add(new List<double> list2());
This is what I have done so far to create a Matrix object and what I'm trying to do is create a Matrix for any amount instead of having to do a fixed amount in my code.
var matrixArrayBuy = CreateMatrix.DenseOfColumnArrays(listMRInfoBuy.ElementAt(0).ListValuesBuy.ToArray(), listMRInfoBuy.ElementAt(1).ListValuesBuy.ToArray(), listMRInfoBuy.ElementAt(2).ListValuesBuy.ToArray(),
listMRInfoBuy.ElementAt(3).ListValuesBuy.ToArray(), listMRInfoBuy.ElementAt(4).ListValuesBuy.ToArray(), listMRInfoBuy.ElementAt(5).ListValuesBuy.ToArray(), listMRInfoBuy.ElementAt(6).ListValuesBuy.ToArray(),
listMRInfoBuy.ElementAt(7).ListValuesBuy.ToArray(), listMRInfoBuy.ElementAt(8).ListValuesBuy.ToArray(), listMRInfoBuy.ElementAt(9).ListValuesBuy.ToArray(), listMRInfoBuy.ElementAt(10).ListValuesBuy.ToArray(),
listMRInfoBuy.ElementAt(11).ListValuesBuy.ToArray());
Upvotes: 0
Views: 188
Reputation: 2067
Not sure what your listMRInfoBuy variable is, but could try something like:
List<double[]> matrixParams = new List<double[]>();
foreach (var item in listMRInfoBuy.Elements)
{
matrixParams.Add(item.ListValuesBuy.ToArray());
}
var matrixArrayBuy = CreateMatrix.DenseOfColumnArrays(matrixParams);
Upvotes: 2